MessageHandler.c 971 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294
  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. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1186. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1187. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1188. }
  1189. //==========================================
  1190. // Check time passed since today
  1191. //==========================================
  1192. long long DiffTimebWithNow(struct timeb ST)
  1193. {
  1194. //return milli-second
  1195. struct timeb ET;
  1196. long long StartTime,StopTime;
  1197. ftime(&ET);
  1198. StartTime=(long long)ST.time;
  1199. StopTime=(long long)ET.time;
  1200. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1201. }
  1202. int getTimePassSinceToday(uint8_t gun_index)
  1203. {
  1204. int result = -1;
  1205. static time_t lastTime[4];
  1206. time_t t;
  1207. struct tm *tmStartToday;
  1208. struct timeb tbStartToday;
  1209. t=time(NULL);
  1210. if(difftime(t, lastTime[gun_index])>0)
  1211. {
  1212. tmStartToday=localtime(&t);
  1213. tmStartToday->tm_hour = 0;
  1214. tmStartToday->tm_min = 0;
  1215. tmStartToday->tm_sec = 0;
  1216. tbStartToday.time = mktime(tmStartToday);
  1217. tbStartToday.millitm = 0;
  1218. result = DiffTimebWithNow(tbStartToday)/1000;
  1219. lastTime[gun_index] = t;
  1220. }
  1221. return result;
  1222. }
  1223. void getNowDatetime(uint8_t *data)
  1224. {
  1225. time_t t = time(NULL);
  1226. struct tm tm = *localtime(&t);
  1227. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1228. }
  1229. int syncDateTimeRTC(uint8_t *data)
  1230. {
  1231. struct ParsingResult
  1232. {
  1233. int result;
  1234. int scanedElement;
  1235. int year;
  1236. int month;
  1237. int mday;
  1238. int hour;
  1239. int min;
  1240. int sec;
  1241. int tz_hour;
  1242. int tz_min;
  1243. float minSec;
  1244. }result;
  1245. struct tm tmOrg;
  1246. struct tm *tmTarget;
  1247. struct timeb tbTarget;
  1248. char buf[128];
  1249. memset(&result, 0x00, sizeof(struct ParsingResult));
  1250. result.result = PASS;
  1251. if(strstr((char*)data, ".") != NULL)
  1252. {
  1253. // Original data with mini second
  1254. if(strstr((char*)data, "Z") != NULL)
  1255. {
  1256. // Original data with Z
  1257. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec,
  1264. &result.minSec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.minSec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. // Original data without mini second
  1284. if(strstr((char*)data, "Z") != NULL)
  1285. {
  1286. // Original data with Z
  1287. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1288. &result.year,
  1289. &result.month,
  1290. &result.mday,
  1291. &result.hour,
  1292. &result.min,
  1293. &result.sec);
  1294. }
  1295. else
  1296. {
  1297. // Original data without Z
  1298. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1299. &result.year,
  1300. &result.month,
  1301. &result.mday,
  1302. &result.hour,
  1303. &result.min,
  1304. &result.sec,
  1305. &result.tz_hour,
  1306. &result.tz_min);
  1307. }
  1308. }
  1309. tmOrg.tm_year = result.year - 1900;
  1310. tmOrg.tm_mon = result.month - 1;
  1311. tmOrg.tm_mday = result.mday;
  1312. tmOrg.tm_hour = result.hour;
  1313. tmOrg.tm_min = result.min;
  1314. tmOrg.tm_sec = result.sec;
  1315. tmOrg.tm_gmtoff = 0;
  1316. tbTarget.time = mktime(&tmOrg);
  1317. tbTarget.timezone = 0;
  1318. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1319. tmTarget = gmtime(&tbTarget.time);
  1320. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1321. //DEBUG_INFO(" org date time: %s\n", data);
  1322. //DEBUG_INFO("parse date time: %s\n", buf);
  1323. system(buf);
  1324. system("/sbin/hwclock -w --systohc");
  1325. if(result.scanedElement < 6)
  1326. result.result = FAIL;
  1327. return result.result;
  1328. }
  1329. //==========================================
  1330. // GetCompositeSchedule logic related function
  1331. //==========================================
  1332. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1333. {
  1334. //return milli-second
  1335. unsigned int StartTime,StopTime;
  1336. StartTime=(unsigned int)ST.time;
  1337. StopTime=(unsigned int)ET.time;
  1338. return (StopTime-StartTime);
  1339. }
  1340. int DiffTimebWithNowSec(struct timeb ST)
  1341. {
  1342. //return milli-second
  1343. struct timeb ET;
  1344. unsigned int StartTime,StopTime;
  1345. ftime(&ET);
  1346. StartTime=(unsigned int)ST.time;
  1347. StopTime=(unsigned int)ET.time;
  1348. return (StopTime-StartTime);
  1349. }
  1350. int getStartStop(uint8_t *start, uint8_t *stop)
  1351. {
  1352. struct ParsingResult
  1353. {
  1354. int result;
  1355. int scanedElement;
  1356. int year;
  1357. int month;
  1358. int mday;
  1359. int hour;
  1360. int min;
  1361. int sec;
  1362. int tz_hour;
  1363. int tz_min;
  1364. float minSec;
  1365. };
  1366. struct ParsingResult parseStart;
  1367. struct ParsingResult parseStop;
  1368. int result = -1;
  1369. struct tm tmStart;
  1370. struct timeb tbStart;
  1371. struct tm tmStop;
  1372. struct timeb tbStop;
  1373. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1374. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1375. // Scan start & stop date time
  1376. if(strstr((char*)start, ".") != NULL)
  1377. {
  1378. // Original data with mini second
  1379. if(strstr((char*)start, "Z") != NULL)
  1380. {
  1381. // Original data with Z
  1382. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1383. &parseStart.year,
  1384. &parseStart.month,
  1385. &parseStart.mday,
  1386. &parseStart.hour,
  1387. &parseStart.min,
  1388. &parseStart.sec,
  1389. &parseStart.minSec);
  1390. }
  1391. else
  1392. {
  1393. // Original data without Z
  1394. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1395. &parseStart.year,
  1396. &parseStart.month,
  1397. &parseStart.mday,
  1398. &parseStart.hour,
  1399. &parseStart.min,
  1400. &parseStart.sec,
  1401. &parseStart.minSec,
  1402. &parseStart.tz_hour,
  1403. &parseStart.tz_min);
  1404. }
  1405. }
  1406. else
  1407. {
  1408. // Original data without mini second
  1409. if(strstr((char*)start, "Z") != NULL)
  1410. {
  1411. // Original data with Z
  1412. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1413. &parseStart.year,
  1414. &parseStart.month,
  1415. &parseStart.mday,
  1416. &parseStart.hour,
  1417. &parseStart.min,
  1418. &parseStart.sec);
  1419. }
  1420. else
  1421. {
  1422. // Original data without Z
  1423. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1424. &parseStart.year,
  1425. &parseStart.month,
  1426. &parseStart.mday,
  1427. &parseStart.hour,
  1428. &parseStart.min,
  1429. &parseStart.sec,
  1430. &parseStart.tz_hour,
  1431. &parseStart.tz_min);
  1432. }
  1433. }
  1434. if(strstr((char*)stop, ".") != NULL)
  1435. {
  1436. // Original data with mini second
  1437. if(strstr((char*)stop, "Z") != NULL)
  1438. {
  1439. // Original data with Z
  1440. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1441. &parseStop.year,
  1442. &parseStop.month,
  1443. &parseStop.mday,
  1444. &parseStop.hour,
  1445. &parseStop.min,
  1446. &parseStop.sec,
  1447. &parseStop.minSec);
  1448. }
  1449. else
  1450. {
  1451. // Original data without Z
  1452. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1453. &parseStop.year,
  1454. &parseStop.month,
  1455. &parseStop.mday,
  1456. &parseStop.hour,
  1457. &parseStop.min,
  1458. &parseStop.sec,
  1459. &parseStop.minSec,
  1460. &parseStop.tz_hour,
  1461. &parseStop.tz_min);
  1462. }
  1463. }
  1464. else
  1465. {
  1466. // Original data without mini second
  1467. if(strstr((char*)stop, "Z") != NULL)
  1468. {
  1469. // Original data with Z
  1470. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1471. &parseStop.year,
  1472. &parseStop.month,
  1473. &parseStop.mday,
  1474. &parseStop.hour,
  1475. &parseStop.min,
  1476. &parseStop.sec);
  1477. }
  1478. else
  1479. {
  1480. // Original data without Z
  1481. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1482. &parseStop.year,
  1483. &parseStop.month,
  1484. &parseStop.mday,
  1485. &parseStop.hour,
  1486. &parseStop.min,
  1487. &parseStop.sec,
  1488. &parseStop.tz_hour,
  1489. &parseStop.tz_min);
  1490. }
  1491. }
  1492. // Calculate date time difference
  1493. if((parseStart.scanedElement >=6) &&
  1494. (parseStop.scanedElement >=6))
  1495. {
  1496. //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);
  1497. //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);
  1498. tmStart.tm_year = parseStart.year - 1900;
  1499. tmStart.tm_mon = parseStart.month - 1;
  1500. tmStart.tm_mday = parseStart.mday;
  1501. tmStart.tm_hour = parseStart.hour;
  1502. tmStart.tm_min = parseStart.min;
  1503. tmStart.tm_sec = parseStart.sec;
  1504. tmStart.tm_gmtoff = 0;
  1505. tbStart.time = mktime(&tmStart);
  1506. tbStart.timezone = 0;
  1507. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1508. tmStop.tm_year = parseStop.year - 1900;
  1509. tmStop.tm_mon = parseStop.month - 1;
  1510. tmStop.tm_mday = parseStop.mday;
  1511. tmStop.tm_hour = parseStop.hour;
  1512. tmStop.tm_min = parseStop.min;
  1513. tmStop.tm_sec = parseStop.sec;
  1514. tmStop.tm_gmtoff = 0;
  1515. tbStop.time = mktime(&tmStop);
  1516. tbStop.timezone = 0;
  1517. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1518. result = DiffTimebSec(tbStart, tbStop);
  1519. //DEBUG_INFO("getStartStop(): %d\n", result);
  1520. }
  1521. else
  1522. {
  1523. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1524. }
  1525. return result;
  1526. }
  1527. int isOvertNow(uint8_t *start)
  1528. {
  1529. int result = NO;
  1530. struct ParsingResult
  1531. {
  1532. int result;
  1533. int scanedElement;
  1534. int year;
  1535. int month;
  1536. int mday;
  1537. int hour;
  1538. int min;
  1539. int sec;
  1540. int tz_hour;
  1541. int tz_min;
  1542. float minSec;
  1543. }parsingResult;
  1544. struct tm tmStart;
  1545. struct timeb tbStart;
  1546. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1547. if(strstr((char*)start, ".") != NULL)
  1548. {
  1549. // Original data with mini second
  1550. if(strstr((char*)start, "Z") != NULL)
  1551. {
  1552. // Original data with Z
  1553. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1554. &parsingResult.year,
  1555. &parsingResult.month,
  1556. &parsingResult.mday,
  1557. &parsingResult.hour,
  1558. &parsingResult.min,
  1559. &parsingResult.sec,
  1560. &parsingResult.minSec);
  1561. }
  1562. else
  1563. {
  1564. // Original data without Z
  1565. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1566. &parsingResult.year,
  1567. &parsingResult.month,
  1568. &parsingResult.mday,
  1569. &parsingResult.hour,
  1570. &parsingResult.min,
  1571. &parsingResult.sec,
  1572. &parsingResult.minSec,
  1573. &parsingResult.tz_hour,
  1574. &parsingResult.tz_min);
  1575. }
  1576. }
  1577. else
  1578. {
  1579. // Original data without mini second
  1580. if(strstr((char*)start, "Z") != NULL)
  1581. {
  1582. // Original data with Z
  1583. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1584. &parsingResult.year,
  1585. &parsingResult.month,
  1586. &parsingResult.mday,
  1587. &parsingResult.hour,
  1588. &parsingResult.min,
  1589. &parsingResult.sec);
  1590. }
  1591. else
  1592. {
  1593. // Original data without Z
  1594. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1595. &parsingResult.year,
  1596. &parsingResult.month,
  1597. &parsingResult.mday,
  1598. &parsingResult.hour,
  1599. &parsingResult.min,
  1600. &parsingResult.sec,
  1601. &parsingResult.tz_hour,
  1602. &parsingResult.tz_min);
  1603. }
  1604. }
  1605. if(parsingResult.scanedElement >= 6)
  1606. {
  1607. tmStart.tm_year = parsingResult.year - 1900;
  1608. tmStart.tm_mon = parsingResult.month - 1;
  1609. tmStart.tm_mday = parsingResult.mday;
  1610. tmStart.tm_hour = parsingResult.hour;
  1611. tmStart.tm_min = parsingResult.min;
  1612. tmStart.tm_sec = parsingResult.sec;
  1613. tmStart.tm_gmtoff = 0;
  1614. tbStart.time = mktime(&tmStart);
  1615. tbStart.timezone = 0;
  1616. tbStart.millitm = 0;
  1617. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1618. if(DiffTimebWithNowSec(tbStart) <= 0)
  1619. result = NO;
  1620. else
  1621. result = YES;
  1622. }
  1623. else
  1624. {
  1625. DEBUG_WARN("Start date parsing error.\n");
  1626. }
  1627. return result;
  1628. }
  1629. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1630. {
  1631. struct ParsingResult
  1632. {
  1633. int result;
  1634. int scanedElement;
  1635. int year;
  1636. int month;
  1637. int mday;
  1638. int hour;
  1639. int min;
  1640. int sec;
  1641. int tz_hour;
  1642. int tz_min;
  1643. float minSec;
  1644. };
  1645. struct ParsingResult parseStart;
  1646. struct ParsingResult parseStop;
  1647. int result = -1;
  1648. struct tm tmStart;
  1649. struct timeb tbStart;
  1650. struct tm tmStop;
  1651. struct timeb tbStop;
  1652. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1653. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1654. // Scan start & stop date time
  1655. if(strstr((char*)start, ".") != NULL)
  1656. {
  1657. // Original data with mini second
  1658. if(strstr((char*)start, "Z") != NULL)
  1659. {
  1660. // Original data with Z
  1661. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1662. &parseStart.year,
  1663. &parseStart.month,
  1664. &parseStart.mday,
  1665. &parseStart.hour,
  1666. &parseStart.min,
  1667. &parseStart.sec,
  1668. &parseStart.minSec);
  1669. }
  1670. else
  1671. {
  1672. // Original data without Z
  1673. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1674. &parseStart.year,
  1675. &parseStart.month,
  1676. &parseStart.mday,
  1677. &parseStart.hour,
  1678. &parseStart.min,
  1679. &parseStart.sec,
  1680. &parseStart.minSec,
  1681. &parseStart.tz_hour,
  1682. &parseStart.tz_min);
  1683. }
  1684. }
  1685. else
  1686. {
  1687. // Original data without mini second
  1688. if(strstr((char*)start, "Z") != NULL)
  1689. {
  1690. // Original data with Z
  1691. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1692. &parseStart.year,
  1693. &parseStart.month,
  1694. &parseStart.mday,
  1695. &parseStart.hour,
  1696. &parseStart.min,
  1697. &parseStart.sec);
  1698. }
  1699. else
  1700. {
  1701. // Original data without Z
  1702. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1703. &parseStart.year,
  1704. &parseStart.month,
  1705. &parseStart.mday,
  1706. &parseStart.hour,
  1707. &parseStart.min,
  1708. &parseStart.sec,
  1709. &parseStart.tz_hour,
  1710. &parseStart.tz_min);
  1711. }
  1712. }
  1713. if(strstr((char*)stop, ".") != NULL)
  1714. {
  1715. // Original data with mini second
  1716. if(strstr((char*)stop, "Z") != NULL)
  1717. {
  1718. // Original data with Z
  1719. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1720. &parseStop.year,
  1721. &parseStop.month,
  1722. &parseStop.mday,
  1723. &parseStop.hour,
  1724. &parseStop.min,
  1725. &parseStop.sec,
  1726. &parseStop.minSec);
  1727. }
  1728. else
  1729. {
  1730. // Original data without Z
  1731. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1732. &parseStop.year,
  1733. &parseStop.month,
  1734. &parseStop.mday,
  1735. &parseStop.hour,
  1736. &parseStop.min,
  1737. &parseStop.sec,
  1738. &parseStop.minSec,
  1739. &parseStop.tz_hour,
  1740. &parseStop.tz_min);
  1741. }
  1742. }
  1743. else
  1744. {
  1745. // Original data without mini second
  1746. if(strstr((char*)stop, "Z") != NULL)
  1747. {
  1748. // Original data with Z
  1749. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1750. &parseStop.year,
  1751. &parseStop.month,
  1752. &parseStop.mday,
  1753. &parseStop.hour,
  1754. &parseStop.min,
  1755. &parseStop.sec);
  1756. }
  1757. else
  1758. {
  1759. // Original data without Z
  1760. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1761. &parseStop.year,
  1762. &parseStop.month,
  1763. &parseStop.mday,
  1764. &parseStop.hour,
  1765. &parseStop.min,
  1766. &parseStop.sec,
  1767. &parseStop.tz_hour,
  1768. &parseStop.tz_min);
  1769. }
  1770. }
  1771. // Calculate date time difference
  1772. if((parseStart.scanedElement >=6) &&
  1773. (parseStop.scanedElement >=6))
  1774. {
  1775. //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);
  1776. //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);
  1777. tmStart.tm_year = parseStart.year - 1900;
  1778. tmStart.tm_mon = parseStart.month - 1;
  1779. tmStart.tm_mday = parseStart.mday;
  1780. tmStart.tm_hour = parseStart.hour;
  1781. tmStart.tm_min = parseStart.min;
  1782. tmStart.tm_sec = parseStart.sec;
  1783. tmStart.tm_gmtoff = 0;
  1784. tbStart.time = mktime(&tmStart);
  1785. tbStart.timezone = 0;
  1786. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1787. tmStop.tm_year = parseStop.year - 1900;
  1788. tmStop.tm_mon = parseStop.month - 1;
  1789. tmStop.tm_mday = parseStop.mday;
  1790. tmStop.tm_hour = parseStop.hour;
  1791. tmStop.tm_min = parseStop.min;
  1792. tmStop.tm_sec = parseStop.sec;
  1793. tmStop.tm_gmtoff = 0;
  1794. tbStop.time = mktime(&tmStop);
  1795. tbStop.timezone = 0;
  1796. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1797. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1798. //DEBUG_INFO("getStartStop(): %d\n", result);
  1799. }
  1800. else
  1801. {
  1802. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1803. }
  1804. return result;
  1805. }
  1806. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1807. {
  1808. FILE *fp;
  1809. char profileFileName[128];
  1810. char *line = NULL;
  1811. size_t len = 0;
  1812. time_t CurrentTime;
  1813. struct tm *tmComposite;
  1814. struct StructChargingProfile maxProfile;
  1815. struct StructChargingProfile compositeProfile;
  1816. uint8_t limitMax=0;
  1817. int compositePeriodIdx = 0;
  1818. CurrentTime = time(NULL);
  1819. tmComposite=localtime(&CurrentTime);
  1820. 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);
  1821. if(isUnitA)
  1822. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. else
  1824. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1825. compositeProfile.ChargingSchedule.Duration = durationReq;
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1829. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1830. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1831. }
  1832. compositeProfile.ChargingProfileId = 0;
  1833. compositeProfile.StackLevel = 99 ;
  1834. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1835. maxProfile.ChargingProfileId = -1;
  1836. maxProfile.ChargingSchedule.Duration = -1;
  1837. system("rm -f /tmp/*.json");
  1838. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1839. // Search max profile
  1840. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1841. if((access(profileFileName, F_OK))!=-1)
  1842. {
  1843. fp = fopen(profileFileName, "r");
  1844. while(getline(&line, &len, fp) != -1)
  1845. {
  1846. json_object *obj = NULL;
  1847. obj = json_tokener_parse(line);
  1848. if(is_error(obj))
  1849. {
  1850. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1851. }
  1852. else
  1853. {
  1854. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1855. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1856. )
  1857. {
  1858. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1859. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1860. )
  1861. {
  1862. struct tm tmFrom, tmTo;
  1863. struct timeb tbFrom, tbTo;
  1864. 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) &&
  1865. (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))
  1866. {
  1867. tmFrom.tm_year -= 1900;
  1868. tmFrom.tm_mon -= 1;
  1869. tbFrom.time = mktime(&tmFrom);
  1870. tmTo.tm_year -= 1900;
  1871. tmTo.tm_mon -= 1;
  1872. tbTo.time = mktime(&tmTo);
  1873. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1874. {
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1880. }
  1881. if(maxProfile.ChargingProfileId == -1)
  1882. DEBUG_INFO("MaxProfile found.\n");
  1883. else
  1884. DEBUG_INFO("MaxProfile updated.\n");
  1885. // Required item
  1886. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1887. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1888. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1889. if(isUnitA)
  1890. {
  1891. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1892. 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++)
  1893. {
  1894. 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"));
  1895. 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?
  1896. 3:
  1897. 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")));
  1898. 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")));
  1899. }
  1900. }
  1901. else
  1902. {
  1903. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1904. 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++)
  1905. {
  1906. 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"));
  1907. 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?
  1908. 3:
  1909. 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")));
  1910. 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));
  1911. }
  1912. }
  1913. // Optional item
  1914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1915. {
  1916. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1917. }
  1918. else
  1919. {
  1920. sprintf((char*)maxProfile.ValidFrom, " ");
  1921. }
  1922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1923. {
  1924. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1925. }
  1926. else
  1927. {
  1928. sprintf((char*)maxProfile.ValidTo, " ");
  1929. }
  1930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1931. {
  1932. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1937. }
  1938. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1939. {
  1940. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1941. }
  1942. else
  1943. {
  1944. maxProfile.TransactionId = -1;
  1945. }
  1946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1947. {
  1948. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1949. }
  1950. else
  1951. {
  1952. maxProfile.ChargingSchedule.Duration = 86400;
  1953. }
  1954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1955. {
  1956. 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")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1961. }
  1962. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1963. {
  1964. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1965. }
  1966. else
  1967. {
  1968. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1969. }
  1970. }
  1971. }
  1972. }
  1973. else
  1974. {
  1975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1976. {
  1977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1980. }
  1981. if(maxProfile.ChargingProfileId == -1)
  1982. DEBUG_INFO("MaxProfile found.\n");
  1983. else
  1984. DEBUG_INFO("MaxProfile updated.\n");
  1985. // Required item
  1986. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1987. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1988. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1989. if(isUnitA)
  1990. {
  1991. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1992. 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++)
  1993. {
  1994. 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"));
  1995. 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?
  1996. 3:
  1997. 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")));
  1998. 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")));
  1999. }
  2000. }
  2001. else
  2002. {
  2003. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2004. 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++)
  2005. {
  2006. 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"));
  2007. 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?
  2008. 3:
  2009. 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")));
  2010. 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));
  2011. }
  2012. }
  2013. // Optional item
  2014. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2015. {
  2016. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2017. }
  2018. else
  2019. {
  2020. sprintf((char*)maxProfile.ValidFrom, " ");
  2021. }
  2022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2023. {
  2024. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2025. }
  2026. else
  2027. {
  2028. sprintf((char*)maxProfile.ValidTo, " ");
  2029. }
  2030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2031. {
  2032. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2037. }
  2038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2039. {
  2040. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2041. }
  2042. else
  2043. {
  2044. maxProfile.TransactionId = -1;
  2045. }
  2046. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2047. {
  2048. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2049. }
  2050. else
  2051. {
  2052. maxProfile.ChargingSchedule.Duration = 86400;
  2053. }
  2054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2055. {
  2056. 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")));
  2057. }
  2058. else
  2059. {
  2060. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2063. {
  2064. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2065. }
  2066. else
  2067. {
  2068. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2069. }
  2070. }
  2071. }
  2072. }
  2073. json_object_put(obj);
  2074. }
  2075. fclose(fp);
  2076. /*
  2077. if(maxProfile.ChargingProfileId !=-1)
  2078. {
  2079. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2080. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2081. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2082. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2083. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2084. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2085. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2086. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2087. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2088. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2089. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2090. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2091. {
  2092. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2093. {
  2094. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2095. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2096. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. DEBUG_INFO("MaxProfile not found.\n");
  2102. DEBUG_INFO("------------------------------------\n");*/
  2103. }
  2104. if(maxProfile.ChargingProfileId != -1)
  2105. {
  2106. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2107. {
  2108. if(maxProfile.ChargingSchedule.Duration != -1)
  2109. {
  2110. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2111. 0:
  2112. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2113. }
  2114. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2115. {
  2116. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2117. {
  2118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. if(idxPeriod > 0)
  2122. {
  2123. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2124. {
  2125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2132. {
  2133. if(maxProfile.ChargingSchedule.Duration != -1)
  2134. {
  2135. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2136. }
  2137. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2138. {
  2139. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2140. {
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2142. if(idxPeriod > 0)
  2143. {
  2144. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2145. {
  2146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. else
  2153. {
  2154. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2155. {
  2156. if(maxProfile.ChargingSchedule.Duration != -1)
  2157. {
  2158. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2159. 0:
  2160. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2161. }
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. if(idxPeriod > 0)
  2170. {
  2171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. else
  2180. {
  2181. if(maxProfile.ChargingSchedule.Duration != -1)
  2182. {
  2183. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2184. 0:
  2185. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2186. }
  2187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2188. {
  2189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. if(idxPeriod > 0)
  2195. {
  2196. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2197. {
  2198. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. /*
  2206. DEBUG_INFO("MaxProfile after align.\n");
  2207. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2208. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2209. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2210. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2211. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2212. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2213. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2214. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2215. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2216. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2217. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2219. {
  2220. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2221. {
  2222. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2223. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2224. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2225. }
  2226. }
  2227. DEBUG_INFO("------------------------------------\n");*/
  2228. }
  2229. // Find each profile period quantity
  2230. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2231. {
  2232. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2233. limitMax = idx+1;
  2234. }
  2235. if(maxProfile.ChargingProfileId != -1)
  2236. {
  2237. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2238. {
  2239. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2240. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2241. (maxProfile.ChargingSchedule.Duration > 0))
  2242. {
  2243. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2244. {
  2245. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2246. compositePeriodIdx++;
  2247. }
  2248. else
  2249. {
  2250. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2251. }
  2252. }
  2253. }
  2254. }
  2255. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2256. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2257. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2258. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2260. {
  2261. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2262. {
  2263. compositeProfile.ChargingProfileId = 1;
  2264. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2265. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2266. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2267. }
  2268. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2269. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2270. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2271. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2272. }
  2273. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2274. if(line)
  2275. free(line);
  2276. }
  2277. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2278. {
  2279. FILE *fp;
  2280. char profileFileName[128];
  2281. char *line = NULL;
  2282. size_t len = 0;
  2283. time_t CurrentTime;
  2284. struct tm *tmComposite;
  2285. struct StructChargingProfile maxProfile;
  2286. struct StructChargingProfile defaultTxProfile;
  2287. struct StructChargingProfile txProfile;
  2288. struct StructChargingProfile compositeProfile;
  2289. struct StructChargingSchedulePeriod tmpPeriod;
  2290. uint8_t limitMax=0;
  2291. uint8_t limitDef=0;
  2292. uint8_t limitTx=0;
  2293. int compositePeriodIdx = 0;
  2294. CurrentTime = time(NULL);
  2295. tmComposite=localtime(&CurrentTime);
  2296. 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);
  2297. if(isUnitA)
  2298. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2299. else
  2300. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2301. compositeProfile.ChargingSchedule.Duration = durationReq;
  2302. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2303. {
  2304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2306. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2307. }
  2308. compositeProfile.ChargingProfileId = 0;
  2309. compositeProfile.StackLevel = 99 ;
  2310. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2311. maxProfile.ChargingProfileId = -1;
  2312. defaultTxProfile.ChargingProfileId = -1;
  2313. txProfile.ChargingProfileId = -1;
  2314. maxProfile.ChargingSchedule.Duration = -1;
  2315. defaultTxProfile.ChargingSchedule.Duration = -1;
  2316. txProfile.ChargingSchedule.Duration = -1;
  2317. system("rm -f /tmp/*.json");
  2318. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2319. /*
  2320. * Search valid charging profile
  2321. */
  2322. //DEBUG_INFO("====================================\n");
  2323. // Search tx profile
  2324. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2325. if((access(profileFileName, F_OK))!=-1)
  2326. {
  2327. fp = fopen(profileFileName, "r");
  2328. while(getline(&line, &len, fp) != -1)
  2329. {
  2330. json_object *obj = NULL;
  2331. obj = json_tokener_parse(line);
  2332. if(is_error(obj))
  2333. {
  2334. DEBUG_ERROR("Parse txProfile from file error.\n");
  2335. }
  2336. else
  2337. {
  2338. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2339. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2340. )
  2341. {
  2342. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2343. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2344. )
  2345. {
  2346. struct tm tmFrom, tmTo;
  2347. struct timeb tbFrom, tbTo;
  2348. 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) &&
  2349. (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))
  2350. {
  2351. tmFrom.tm_year -= 1900;
  2352. tmFrom.tm_mon -= 1;
  2353. tbFrom.time = mktime(&tmFrom);
  2354. tmTo.tm_year -= 1900;
  2355. tmTo.tm_mon -= 1;
  2356. tbTo.time = mktime(&tmTo);
  2357. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2358. {
  2359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2360. {
  2361. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2364. }
  2365. if(txProfile.ChargingProfileId == -1)
  2366. DEBUG_INFO("TxProfile found.\n");
  2367. else
  2368. DEBUG_INFO("TxProfile updated.\n");
  2369. // Required item
  2370. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2371. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2372. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2373. if(isUnitA)
  2374. {
  2375. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2376. 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++)
  2377. {
  2378. 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"));
  2379. 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?
  2380. 3:
  2381. 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")));
  2382. 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")));
  2383. }
  2384. }
  2385. else
  2386. {
  2387. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2388. 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++)
  2389. {
  2390. 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"));
  2391. 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?
  2392. 3:
  2393. 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")));
  2394. 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));
  2395. }
  2396. }
  2397. // Optional item
  2398. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2399. {
  2400. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2401. }
  2402. else
  2403. {
  2404. sprintf((char*)txProfile.ValidFrom, " ");
  2405. }
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidTo, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.RecurrencyKind, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2423. {
  2424. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2425. }
  2426. else
  2427. {
  2428. txProfile.TransactionId = -1;
  2429. }
  2430. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2431. {
  2432. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.ChargingSchedule.Duration = 86400;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2439. {
  2440. 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")));
  2441. }
  2442. else
  2443. {
  2444. 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));
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2447. {
  2448. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2449. }
  2450. else
  2451. {
  2452. txProfile.ChargingSchedule.MinChargingRate = -1;
  2453. }
  2454. }
  2455. }
  2456. }
  2457. else
  2458. {
  2459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2460. {
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2462. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2464. }
  2465. if(txProfile.ChargingProfileId == -1)
  2466. DEBUG_INFO("TxProfile found.\n");
  2467. else
  2468. DEBUG_INFO("TxProfile updated.\n");
  2469. // Required item
  2470. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2471. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2472. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2473. if(isUnitA)
  2474. {
  2475. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2476. 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++)
  2477. {
  2478. 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"));
  2479. 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?
  2480. 3:
  2481. 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")));
  2482. 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")));
  2483. }
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2488. 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++)
  2489. {
  2490. 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"));
  2491. 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?
  2492. 3:
  2493. 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")));
  2494. 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));
  2495. }
  2496. }
  2497. // Optional item
  2498. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2499. {
  2500. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2501. }
  2502. else
  2503. {
  2504. sprintf((char*)txProfile.ValidFrom, " ");
  2505. }
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidTo, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.RecurrencyKind, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2523. {
  2524. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2525. }
  2526. else
  2527. {
  2528. txProfile.TransactionId = -1;
  2529. }
  2530. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2531. {
  2532. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.ChargingSchedule.Duration = 86400;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2539. {
  2540. 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")));
  2541. }
  2542. else
  2543. {
  2544. 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));
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2547. {
  2548. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2549. }
  2550. else
  2551. {
  2552. txProfile.ChargingSchedule.MinChargingRate = -1;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. json_object_put(obj);
  2558. }
  2559. fclose(fp);
  2560. /*
  2561. if(txProfile.ChargingProfileId != -1)
  2562. {
  2563. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2564. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2565. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2566. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2567. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2568. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2569. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2570. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2571. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2572. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2573. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2575. {
  2576. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2577. {
  2578. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2579. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2580. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2581. }
  2582. }
  2583. }
  2584. else
  2585. DEBUG_INFO("TxProfile not found.\n");*/
  2586. }
  2587. // Search default tx profile
  2588. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2589. if((access(profileFileName, F_OK))==-1)
  2590. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2591. if((access(profileFileName, F_OK))!=-1)
  2592. {
  2593. fp = fopen(profileFileName, "r");
  2594. while(getline(&line, &len, fp) != -1)
  2595. {
  2596. json_object *obj = NULL;
  2597. obj = json_tokener_parse(line);
  2598. if(is_error(obj))
  2599. {
  2600. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2601. }
  2602. else
  2603. {
  2604. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2605. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2606. )
  2607. {
  2608. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2609. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. )
  2611. {
  2612. struct tm tmFrom, tmTo;
  2613. struct timeb tbFrom, tbTo;
  2614. 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) &&
  2615. (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))
  2616. {
  2617. tmFrom.tm_year -= 1900;
  2618. tmFrom.tm_mon -= 1;
  2619. tbFrom.time = mktime(&tmFrom);
  2620. tmTo.tm_year -= 1900;
  2621. tmTo.tm_mon -= 1;
  2622. tbTo.time = mktime(&tmTo);
  2623. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2624. {
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2628. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2629. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2630. }
  2631. if(defaultTxProfile.ChargingProfileId == -1)
  2632. DEBUG_INFO("TxDefaultProfile found.\n");
  2633. else
  2634. DEBUG_INFO("TxDefaultProfile updated.\n");
  2635. // Required item
  2636. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2637. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2638. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2639. if(isUnitA)
  2640. {
  2641. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2642. 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++)
  2643. {
  2644. 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"));
  2645. 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?
  2646. 3:
  2647. 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")));
  2648. 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")));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2654. 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++)
  2655. {
  2656. 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"));
  2657. 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?
  2658. 3:
  2659. 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")));
  2660. 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));
  2661. }
  2662. }
  2663. // Optional item
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2665. {
  2666. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2667. }
  2668. else
  2669. {
  2670. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2671. }
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2689. {
  2690. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2691. }
  2692. else
  2693. {
  2694. defaultTxProfile.TransactionId = -1;
  2695. }
  2696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2697. {
  2698. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2705. {
  2706. 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")));
  2707. }
  2708. else
  2709. {
  2710. 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));
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2715. }
  2716. else
  2717. {
  2718. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. else
  2724. {
  2725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2726. {
  2727. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2729. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2730. }
  2731. if(defaultTxProfile.ChargingProfileId == -1)
  2732. DEBUG_INFO("TxDefaultProfile found.\n");
  2733. else
  2734. DEBUG_INFO("TxDefaultProfile updated.\n");
  2735. // Required item
  2736. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2737. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2738. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2739. if(isUnitA)
  2740. {
  2741. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2742. 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++)
  2743. {
  2744. 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"));
  2745. 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?
  2746. 3:
  2747. 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")));
  2748. 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")));
  2749. }
  2750. }
  2751. else
  2752. {
  2753. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2754. 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++)
  2755. {
  2756. 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"));
  2757. 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?
  2758. 3:
  2759. 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")));
  2760. 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));
  2761. }
  2762. }
  2763. // Optional item
  2764. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2765. {
  2766. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2767. }
  2768. else
  2769. {
  2770. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2771. }
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2789. {
  2790. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2791. }
  2792. else
  2793. {
  2794. defaultTxProfile.TransactionId = -1;
  2795. }
  2796. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2797. {
  2798. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2805. {
  2806. 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")));
  2807. }
  2808. else
  2809. {
  2810. 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));
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2815. }
  2816. else
  2817. {
  2818. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2819. }
  2820. }
  2821. }
  2822. }
  2823. json_object_put(obj);
  2824. }
  2825. fclose(fp);
  2826. /*
  2827. if(defaultTxProfile.ChargingProfileId != -1)
  2828. {
  2829. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2830. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2831. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2832. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2833. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2834. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2835. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2836. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2837. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2838. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2839. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2841. {
  2842. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2843. {
  2844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2847. }
  2848. }
  2849. }
  2850. else
  2851. DEBUG_INFO("TxDefaultProfile not found.\n");
  2852. DEBUG_INFO("------------------------------------\n");*/
  2853. }
  2854. // Search max profile
  2855. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2856. if((access(profileFileName, F_OK))!=-1)
  2857. {
  2858. fp = fopen(profileFileName, "r");
  2859. while(getline(&line, &len, fp) != -1)
  2860. {
  2861. json_object *obj = NULL;
  2862. obj = json_tokener_parse(line);
  2863. if(is_error(obj))
  2864. {
  2865. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2866. }
  2867. else
  2868. {
  2869. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2870. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2871. )
  2872. {
  2873. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2874. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2875. )
  2876. {
  2877. struct tm tmFrom, tmTo;
  2878. struct timeb tbFrom, tbTo;
  2879. 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) &&
  2880. (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))
  2881. {
  2882. tmFrom.tm_year -= 1900;
  2883. tmFrom.tm_mon -= 1;
  2884. tbFrom.time = mktime(&tmFrom);
  2885. tmTo.tm_year -= 1900;
  2886. tmTo.tm_mon -= 1;
  2887. tbTo.time = mktime(&tmTo);
  2888. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2889. {
  2890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2893. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2895. }
  2896. if(maxProfile.ChargingProfileId == -1)
  2897. DEBUG_INFO("MaxProfile found.\n");
  2898. else
  2899. DEBUG_INFO("MaxProfile updated.\n");
  2900. // Required item
  2901. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2902. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2903. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2904. if(isUnitA)
  2905. {
  2906. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2907. 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++)
  2908. {
  2909. 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"));
  2910. 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?
  2911. 3:
  2912. 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")));
  2913. 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")));
  2914. }
  2915. }
  2916. else
  2917. {
  2918. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2919. 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++)
  2920. {
  2921. 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"));
  2922. 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?
  2923. 3:
  2924. 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")));
  2925. 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));
  2926. }
  2927. }
  2928. // Optional item
  2929. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2930. {
  2931. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2932. }
  2933. else
  2934. {
  2935. sprintf((char*)maxProfile.ValidFrom, " ");
  2936. }
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidTo, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2954. {
  2955. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2956. }
  2957. else
  2958. {
  2959. maxProfile.TransactionId = -1;
  2960. }
  2961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2962. {
  2963. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.ChargingSchedule.Duration = 86400;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2970. {
  2971. 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")));
  2972. }
  2973. else
  2974. {
  2975. 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));
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2978. {
  2979. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2980. }
  2981. else
  2982. {
  2983. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2984. }
  2985. }
  2986. }
  2987. }
  2988. else
  2989. {
  2990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2991. {
  2992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2995. }
  2996. if(maxProfile.ChargingProfileId == -1)
  2997. DEBUG_INFO("MaxProfile found.\n");
  2998. else
  2999. DEBUG_INFO("MaxProfile updated.\n");
  3000. // Required item
  3001. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3002. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3003. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3004. if(isUnitA)
  3005. {
  3006. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3007. 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++)
  3008. {
  3009. 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"));
  3010. 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?
  3011. 3:
  3012. 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")));
  3013. 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")));
  3014. }
  3015. }
  3016. else
  3017. {
  3018. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3019. 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++)
  3020. {
  3021. 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"));
  3022. 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?
  3023. 3:
  3024. 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")));
  3025. 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));
  3026. }
  3027. }
  3028. // Optional item
  3029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3030. {
  3031. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3032. }
  3033. else
  3034. {
  3035. sprintf((char*)maxProfile.ValidFrom, " ");
  3036. }
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidTo, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3054. {
  3055. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3056. }
  3057. else
  3058. {
  3059. maxProfile.TransactionId = -1;
  3060. }
  3061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3062. {
  3063. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.ChargingSchedule.Duration = 86400;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3070. {
  3071. 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")));
  3072. }
  3073. else
  3074. {
  3075. 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));
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3078. {
  3079. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3080. }
  3081. else
  3082. {
  3083. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3084. }
  3085. }
  3086. }
  3087. }
  3088. json_object_put(obj);
  3089. }
  3090. fclose(fp);
  3091. /*
  3092. if(maxProfile.ChargingProfileId !=-1)
  3093. {
  3094. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3095. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3096. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3097. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3098. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3099. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3100. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3101. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3102. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3103. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3104. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3105. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3106. {
  3107. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3108. {
  3109. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3110. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3111. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3112. }
  3113. }
  3114. }
  3115. else
  3116. DEBUG_INFO("MaxProfile not found.\n");
  3117. DEBUG_INFO("------------------------------------\n");*/
  3118. }
  3119. /*
  3120. * Align found profile start schedule & periods
  3121. */
  3122. //DEBUG_INFO("====================================\n");
  3123. /*
  3124. // For local test usage, force modify found profile start schedule info
  3125. 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);
  3126. 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);
  3127. 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);
  3128. */
  3129. if(txProfile.ChargingProfileId != -1)
  3130. {
  3131. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3132. {
  3133. if(txProfile.ChargingSchedule.Duration != -1)
  3134. {
  3135. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3136. 0:
  3137. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3138. }
  3139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3140. {
  3141. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3142. {
  3143. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. if(idxPeriod > 0)
  3147. {
  3148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3149. {
  3150. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3157. {
  3158. if(txProfile.ChargingSchedule.Duration != -1)
  3159. {
  3160. 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?
  3161. 0:
  3162. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3163. }
  3164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3165. {
  3166. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3167. {
  3168. 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?
  3169. 0:
  3170. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. if(idxPeriod > 0)
  3172. {
  3173. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3174. {
  3175. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3176. }
  3177. }
  3178. }
  3179. }
  3180. }
  3181. else
  3182. {
  3183. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3184. {
  3185. if(txProfile.ChargingSchedule.Duration != -1)
  3186. {
  3187. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3188. 0:
  3189. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3190. }
  3191. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3192. {
  3193. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3194. {
  3195. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. if(idxPeriod > 0)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3201. {
  3202. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3203. }
  3204. }
  3205. }
  3206. }
  3207. }
  3208. else
  3209. {
  3210. if(txProfile.ChargingSchedule.Duration != -1)
  3211. {
  3212. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3213. 0:
  3214. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3215. }
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3219. {
  3220. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. if(idxPeriod > 0)
  3224. {
  3225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3226. {
  3227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. /*
  3235. DEBUG_INFO("txProfile after align.\n");
  3236. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3237. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3238. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3239. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3240. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3242. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3243. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3244. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3245. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3246. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3248. {
  3249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3250. {
  3251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3254. }
  3255. }*/
  3256. }
  3257. if(defaultTxProfile.ChargingProfileId != -1)
  3258. {
  3259. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3260. {
  3261. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3262. {
  3263. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3264. 0:
  3265. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3266. }
  3267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. if(idxPeriod > 0)
  3275. {
  3276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3277. {
  3278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3279. }
  3280. }
  3281. }
  3282. }
  3283. }
  3284. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3285. {
  3286. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3287. {
  3288. 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?
  3289. 0:
  3290. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3291. }
  3292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3295. {
  3296. 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?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. if(idxPeriod > 0)
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3302. {
  3303. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3312. {
  3313. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3314. {
  3315. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3316. 0:
  3317. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3318. }
  3319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. if(idxPeriod > 0)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3329. {
  3330. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3331. }
  3332. }
  3333. }
  3334. }
  3335. }
  3336. else
  3337. {
  3338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3339. {
  3340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3341. 0:
  3342. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3343. }
  3344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. if(idxPeriod > 0)
  3352. {
  3353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3354. {
  3355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. }
  3362. /*
  3363. DEBUG_INFO("defaultTxProfile after align.\n");
  3364. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3365. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3366. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3367. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3368. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3369. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3370. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3371. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3372. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3373. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3374. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3378. {
  3379. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3380. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3381. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3382. }
  3383. }
  3384. DEBUG_INFO("------------------------------------\n");*/
  3385. }
  3386. if(maxProfile.ChargingProfileId != -1)
  3387. {
  3388. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3389. {
  3390. if(maxProfile.ChargingSchedule.Duration != -1)
  3391. {
  3392. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3393. 0:
  3394. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3395. }
  3396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3397. {
  3398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. if(idxPeriod > 0)
  3404. {
  3405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3406. {
  3407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3414. {
  3415. if(maxProfile.ChargingSchedule.Duration != -1)
  3416. {
  3417. 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?
  3418. 0:
  3419. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3420. }
  3421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3422. {
  3423. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3424. {
  3425. 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?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. if(idxPeriod > 0)
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3431. {
  3432. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3433. }
  3434. }
  3435. }
  3436. }
  3437. }
  3438. else
  3439. {
  3440. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3441. {
  3442. if(maxProfile.ChargingSchedule.Duration != -1)
  3443. {
  3444. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3445. 0:
  3446. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3447. }
  3448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3449. {
  3450. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. if(idxPeriod > 0)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3458. {
  3459. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. }
  3465. else
  3466. {
  3467. if(maxProfile.ChargingSchedule.Duration != -1)
  3468. {
  3469. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3470. 0:
  3471. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3472. }
  3473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3474. {
  3475. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. if(idxPeriod > 0)
  3481. {
  3482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3483. {
  3484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. }
  3491. /*
  3492. DEBUG_INFO("MaxProfile after align.\n");
  3493. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3494. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3495. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3496. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3497. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3498. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3499. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3500. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3501. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3502. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3503. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3505. {
  3506. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3507. {
  3508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3511. }
  3512. }
  3513. DEBUG_INFO("------------------------------------\n");*/
  3514. }
  3515. /*
  3516. * Merge to conposite schedule
  3517. */
  3518. //DEBUG_INFO("====================================\n");
  3519. // Find each profile period quantity
  3520. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3521. {
  3522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3523. limitMax = idx+1;
  3524. }
  3525. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3526. {
  3527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3528. limitDef = idx+1;
  3529. }
  3530. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3533. limitTx = idx+1;
  3534. }
  3535. // TxProfile found, composite schedule based on it
  3536. if(txProfile.ChargingProfileId != -1)
  3537. {
  3538. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3539. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3540. {
  3541. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3542. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3543. (txProfile.ChargingSchedule.Duration > 0))
  3544. {
  3545. if(maxProfile.ChargingProfileId != -1)
  3546. {
  3547. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3550. {
  3551. if((maxProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3554. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3555. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3556. }
  3557. else
  3558. {
  3559. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3560. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3561. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3562. }
  3563. }
  3564. if(idxMaxPeriod == (limitMax-1))
  3565. {
  3566. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3567. {
  3568. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3569. {
  3570. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3571. compositePeriodIdx++;
  3572. }
  3573. else
  3574. {
  3575. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }
  3581. else
  3582. {
  3583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3584. {
  3585. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3586. compositePeriodIdx++;
  3587. }
  3588. else
  3589. {
  3590. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3591. }
  3592. }
  3593. }
  3594. if(idxTxPeriod == (limitTx-1))
  3595. {
  3596. if(defaultTxProfile.ChargingProfileId != -1)
  3597. {
  3598. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3599. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3600. {
  3601. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3602. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3603. (defaultTxProfile.ChargingSchedule.Duration>0))
  3604. {
  3605. if(maxProfile.ChargingProfileId != -1)
  3606. {
  3607. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3608. {
  3609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3610. {
  3611. if((maxProfile.ChargingSchedule.Duration > 0))
  3612. {
  3613. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3614. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3615. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3616. }
  3617. else
  3618. {
  3619. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3620. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3621. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3622. }
  3623. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3624. {
  3625. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3626. {
  3627. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3628. compositePeriodIdx++;
  3629. }
  3630. else
  3631. {
  3632. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3633. }
  3634. }
  3635. // Delete duplicate period
  3636. if(compositePeriodIdx > 1)
  3637. {
  3638. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3639. {
  3640. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3641. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3642. compositePeriodIdx -= 1;
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3649. {
  3650. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3651. compositePeriodIdx++;
  3652. }
  3653. else
  3654. {
  3655. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3656. }
  3657. break;
  3658. }
  3659. }
  3660. }
  3661. else
  3662. {
  3663. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3664. {
  3665. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3666. compositePeriodIdx++;
  3667. }
  3668. else
  3669. {
  3670. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3671. }
  3672. }
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3680. else if(defaultTxProfile.ChargingProfileId != -1)
  3681. {
  3682. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3683. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3684. {
  3685. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3686. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3687. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3688. {
  3689. if(maxProfile.ChargingProfileId != -1)
  3690. {
  3691. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3692. {
  3693. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3694. {
  3695. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3696. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3697. if((maxProfile.ChargingSchedule.Duration > 0))
  3698. {
  3699. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3700. }
  3701. else
  3702. {
  3703. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3704. }
  3705. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3706. {
  3707. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3708. {
  3709. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3710. compositePeriodIdx++;
  3711. }
  3712. else
  3713. {
  3714. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3715. }
  3716. }
  3717. // Delete duplicate period
  3718. if(compositePeriodIdx > 1)
  3719. {
  3720. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3721. {
  3722. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3723. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3724. compositePeriodIdx -= 1;
  3725. }
  3726. }
  3727. }
  3728. else
  3729. {
  3730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3731. {
  3732. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3733. compositePeriodIdx++;
  3734. }
  3735. else
  3736. {
  3737. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3738. }
  3739. break;
  3740. }
  3741. }
  3742. }
  3743. else
  3744. {
  3745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3746. {
  3747. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3748. compositePeriodIdx++;
  3749. }
  3750. else
  3751. {
  3752. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3753. }
  3754. }
  3755. }
  3756. }
  3757. }
  3758. // Fill other period by MaxProfile
  3759. if(maxProfile.ChargingProfileId != -1)
  3760. {
  3761. if(compositePeriodIdx==0)
  3762. {
  3763. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3764. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3765. {
  3766. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3767. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3768. (maxProfile.ChargingSchedule.Duration > 0))
  3769. {
  3770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3771. {
  3772. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3773. compositePeriodIdx++;
  3774. }
  3775. else
  3776. {
  3777. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3778. }
  3779. }
  3780. }
  3781. }
  3782. else
  3783. {
  3784. int lastCompositePeriodIdx = compositePeriodIdx;
  3785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3786. {
  3787. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3788. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3789. (maxProfile.ChargingSchedule.Duration > 0))
  3790. {
  3791. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3792. {
  3793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3794. {
  3795. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3796. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3797. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3798. }
  3799. else
  3800. {
  3801. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3802. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3803. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3804. }
  3805. }
  3806. if(tmpPeriod.Limit != -1)
  3807. {
  3808. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3809. {
  3810. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3811. {
  3812. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3813. compositePeriodIdx++;
  3814. }
  3815. else
  3816. {
  3817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3818. }
  3819. }
  3820. // Delete duplicate period
  3821. if(compositePeriodIdx > 1)
  3822. {
  3823. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3824. {
  3825. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3826. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3827. compositePeriodIdx -= 1;
  3828. }
  3829. }
  3830. }
  3831. }
  3832. }
  3833. }
  3834. }
  3835. compositeProfile.ChargingSchedule.Duration = durationReq;
  3836. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3837. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3838. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3839. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3841. {
  3842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3843. {
  3844. compositeProfile.ChargingProfileId = 1;
  3845. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3846. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3847. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3848. }
  3849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3853. }
  3854. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3855. if(line)
  3856. free(line);
  3857. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3858. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3859. }
  3860. //==========================================
  3861. // Init all share memory
  3862. //==========================================
  3863. int InitShareMemory()
  3864. {
  3865. int result = PASS;
  3866. int MeterSMId;
  3867. //creat ShmSysConfigAndInfo
  3868. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3869. {
  3870. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3871. result = FAIL;
  3872. }
  3873. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3874. {
  3875. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3876. result = FAIL;
  3877. }
  3878. else
  3879. {}
  3880. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3881. {
  3882. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3883. result = FAIL;
  3884. }
  3885. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3886. {
  3887. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3888. result = FAIL;
  3889. }
  3890. else
  3891. {}
  3892. //creat ShmPsuData
  3893. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3894. {
  3895. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3899. {
  3900. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3901. result = FAIL;
  3902. }
  3903. else
  3904. {}
  3905. //creat ShmOCPP16Data
  3906. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3907. {
  3908. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3909. result = FAIL;
  3910. }
  3911. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3912. {
  3913. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3914. result = FAIL;
  3915. }
  3916. else
  3917. {}
  3918. /****************************** For Initial Settings************************************************/
  3919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3921. // allocate Configuration memory address
  3922. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3923. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3924. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3925. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3926. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3927. //offline MeterValue Interval
  3928. TempMeterValueInterval = 0;
  3929. return result;
  3930. }
  3931. int ProcessShareMemory()
  3932. {
  3933. int result = PASS;
  3934. if(InitShareMemory() == FAIL)
  3935. {
  3936. DEBUG_ERROR("InitShareMemory NG\n");
  3937. if(ShmStatusCodeData!=NULL)
  3938. {
  3939. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3940. }
  3941. result = FAIL;
  3942. }
  3943. // Model name parsing
  3944. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3945. {
  3946. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3947. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3948. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3949. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3950. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3951. ) // 'D' means DC
  3952. {
  3953. // DO series
  3954. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3955. {
  3956. gunTotalNumber += 1;
  3957. gunType[gun_index] = GUN_TYPE_DO;
  3958. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3959. {
  3960. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3961. {
  3962. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3963. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3964. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3965. }
  3966. }
  3967. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3968. {
  3969. case Gun_Type_Chademo:
  3970. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3971. break;
  3972. case Gun_Type_CCS_2:
  3973. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3974. break;
  3975. case Gun_Type_GB:
  3976. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3977. break;
  3978. case Gun_Type_AC:
  3979. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3980. break;
  3981. default:
  3982. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3983. break;
  3984. }
  3985. }
  3986. }
  3987. else
  3988. {
  3989. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3990. {
  3991. gunTotalNumber += 1;
  3992. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3993. {
  3994. case Gun_Type_Chademo:
  3995. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3996. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3997. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3998. {
  3999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4000. {
  4001. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4002. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4003. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4004. }
  4005. }
  4006. break;
  4007. case Gun_Type_CCS_2:
  4008. gunType[gun_index] = GUN_TYPE_CCS;
  4009. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4010. for (int index = 0; index < CCS_QUANTITY; index++)
  4011. {
  4012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4013. {
  4014. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4015. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4016. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4017. }
  4018. }
  4019. break;
  4020. case Gun_Type_GB:
  4021. gunType[gun_index] = GUN_TYPE_GBT;
  4022. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4023. for (int index = 0; index < GB_QUANTITY; index++)
  4024. {
  4025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4026. {
  4027. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4028. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4029. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4030. }
  4031. }
  4032. break;
  4033. case Gun_Type_AC:
  4034. gunType[gun_index] = GUN_TYPE_AC;
  4035. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4036. for (int index = 0; index < AC_QUANTITY; index++)
  4037. {
  4038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4039. {
  4040. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4041. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4042. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4043. }
  4044. }
  4045. break;
  4046. default:
  4047. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. }
  4053. else
  4054. {
  4055. DEBUG_ERROR("Model name parsing fail.\n");
  4056. result = FAIL;
  4057. }
  4058. if(result != PASS)sleep(5);
  4059. return result;
  4060. }
  4061. void checkRemoteStart(uint8_t connectorIdInt)
  4062. {
  4063. uint8_t tempIndex;
  4064. int result = PASS;
  4065. char cmdBuf[512];
  4066. //check Transaction active
  4067. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4070. {
  4071. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4072. }
  4073. else
  4074. {
  4075. tempIndex = connectorIdInt -1;
  4076. }
  4077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4080. {
  4081. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4082. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4083. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4084. {
  4085. //Reserved
  4086. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4087. }
  4088. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4090. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4091. {
  4092. //Reserved
  4093. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4094. result = FAIL;
  4095. goto end;
  4096. }
  4097. else
  4098. {
  4099. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4101. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4103. {
  4104. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4105. result = FAIL;
  4106. goto end;
  4107. }
  4108. }//END FOR ELSE
  4109. }
  4110. }// END FOR CHAdeMO_QUANTITY
  4111. }
  4112. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4117. }
  4118. else
  4119. {
  4120. tempIndex = connectorIdInt -1;
  4121. }
  4122. for (int index = 0; index < CCS_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4125. {
  4126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4128. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4129. {
  4130. //Reserved
  4131. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4132. }
  4133. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4134. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4135. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4136. {
  4137. //Reserved
  4138. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4139. result = FAIL;
  4140. goto end;
  4141. }
  4142. else
  4143. {
  4144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4145. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4146. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4147. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4148. {
  4149. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4150. result = FAIL;
  4151. goto end;
  4152. }
  4153. }// END FOR ELSE
  4154. }
  4155. }// END FOR CCS_QUANTITY
  4156. }
  4157. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4158. {
  4159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4160. {
  4161. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4162. }
  4163. else
  4164. {
  4165. tempIndex = connectorIdInt -1;
  4166. }
  4167. for (int index = 0; index < GB_QUANTITY; index++)
  4168. {
  4169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4170. {
  4171. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4172. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4173. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4174. {
  4175. //Reserved
  4176. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4177. }
  4178. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4179. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4180. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4181. {
  4182. //Reserved
  4183. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4184. result = FAIL;
  4185. goto end;
  4186. }
  4187. else
  4188. {
  4189. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4190. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4191. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4192. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4193. {
  4194. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4195. result = FAIL;
  4196. goto end;
  4197. }
  4198. }// END FOR ELSE
  4199. }
  4200. } // END FOR GB_QUANTITY
  4201. }
  4202. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4203. {
  4204. tempIndex = connectorIdInt -1;
  4205. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4206. {
  4207. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4208. {
  4209. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4211. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4212. {
  4213. //Reserved
  4214. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4215. }
  4216. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4217. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4219. {
  4220. //Reserved
  4221. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4222. result = FAIL;
  4223. goto end;
  4224. }
  4225. else
  4226. {
  4227. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4228. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4229. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4230. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4231. {
  4232. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4233. result = FAIL;
  4234. goto end;
  4235. }
  4236. }// END FOR ELSE
  4237. }
  4238. } // END FOR GB_QUANTITY
  4239. }
  4240. else
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4243. {
  4244. tempIndex = 2;
  4245. }
  4246. else
  4247. {
  4248. tempIndex = connectorIdInt -1;
  4249. }
  4250. for (int index = 0; index < AC_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4253. {
  4254. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4256. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4257. {
  4258. //Reserved
  4259. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4260. }
  4261. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4263. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4264. {
  4265. //Reserved
  4266. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4267. result = FAIL;
  4268. goto end;
  4269. }
  4270. else
  4271. {
  4272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4274. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4276. {
  4277. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4278. result = FAIL;
  4279. goto end;
  4280. }
  4281. }//END FOR ELSE
  4282. }
  4283. }// END FOR AC_QUANTITY
  4284. }
  4285. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4286. {
  4287. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4288. {
  4289. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4290. {
  4291. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4292. system(cmdBuf);
  4293. }
  4294. }
  4295. else
  4296. {
  4297. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4298. result = FAIL;
  4299. }
  4300. }
  4301. end:
  4302. if(result == PASS)
  4303. {
  4304. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4305. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4306. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4307. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4308. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4309. }
  4310. }
  4311. void CheckSystemValue(void)
  4312. {
  4313. char filenmae[100]={0};
  4314. char str[100]={0};
  4315. int tempIndex = 0;
  4316. //===============================
  4317. // send Heartbeat
  4318. //===============================
  4319. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4320. {
  4321. //parameter for test
  4322. sendHeartbeatRequest(0);
  4323. //===========================
  4324. // Reset Waiting Time
  4325. //===========================
  4326. HeartBeatWithNOResponse += 1;
  4327. }
  4328. //===============================
  4329. // Credit deduct report
  4330. //===============================
  4331. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4332. {
  4333. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4334. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4335. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4336. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4337. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4338. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4339. }
  4340. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4341. {
  4342. OCPP_query_deduct_info();
  4343. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4344. }
  4345. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4346. {
  4347. // ClockAlign MeterValue
  4348. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4349. {
  4350. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4351. {
  4352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4353. {
  4354. tempIndex = ((gun_index==2) ? 1: 0);
  4355. }
  4356. else
  4357. {
  4358. tempIndex = gun_index;
  4359. }
  4360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4361. {
  4362. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4363. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4364. {
  4365. reqClockAlignMeter[gun_index] = 1;
  4366. }
  4367. }// End for CHAdeMO
  4368. }
  4369. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4370. {
  4371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4372. {
  4373. tempIndex = ((gun_index==2) ? 1: 0);
  4374. }
  4375. else
  4376. {
  4377. tempIndex = gun_index;
  4378. }
  4379. for (int index = 0; index < CCS_QUANTITY; index++)
  4380. {
  4381. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4382. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4383. {
  4384. reqClockAlignMeter[gun_index] = 1;
  4385. }
  4386. } // End for CCS
  4387. }
  4388. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4389. {
  4390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4391. {
  4392. tempIndex = ((gun_index==2) ? 1: 0);
  4393. }
  4394. else
  4395. {
  4396. tempIndex = gun_index;
  4397. }
  4398. for (int index = 0; index < GB_QUANTITY; index++)
  4399. {
  4400. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4401. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4402. {
  4403. reqClockAlignMeter[gun_index] = 1;
  4404. }
  4405. }// End for GB
  4406. }
  4407. else if(gunType[gun_index] == GUN_TYPE_DO)
  4408. {
  4409. tempIndex = gun_index;
  4410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4411. {
  4412. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4413. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4414. {
  4415. reqClockAlignMeter[gun_index] = 1;
  4416. }
  4417. }
  4418. }
  4419. else
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4422. {
  4423. tempIndex = 2;
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < AC_QUANTITY; index++)
  4430. {
  4431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4432. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4433. {
  4434. reqClockAlignMeter[gun_index] = 1;
  4435. }
  4436. }//End for AC
  4437. }
  4438. }
  4439. }
  4440. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4441. {
  4442. //==========================================
  4443. // Check remote start without connector id
  4444. //==========================================
  4445. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4446. {
  4447. int connectorIdInt = -1;
  4448. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4449. {
  4450. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4451. {
  4452. connectorIdInt = (gun_index+1);
  4453. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4454. checkRemoteStart(connectorIdInt);
  4455. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4456. break;
  4457. }
  4458. }
  4459. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4460. {
  4461. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4462. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4463. }
  4464. }
  4465. //==========================================
  4466. // csu trigger DataTransferReq
  4467. //==========================================
  4468. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4469. {
  4470. sendDataTransferRequest(gun_index);
  4471. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4472. }
  4473. //==========================================
  4474. // CSU Trigger Authorize Request
  4475. //==========================================
  4476. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4477. {
  4478. sendAuthorizeRequest(0);
  4479. authorizeRetryTimes = authorizeRetryTimes + 1;
  4480. if(authorizeRetryTimes < 3)
  4481. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4482. }
  4483. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4484. {
  4485. authorizeRetryTimes = 0;
  4486. SetOcppConnStatus(FALSE);
  4487. server_sign = FALSE;
  4488. }
  4489. 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))
  4490. {
  4491. sendAuthorizeRequest(0);
  4492. }
  4493. //==========================================
  4494. // Charger start transaction
  4495. //==========================================
  4496. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4497. {
  4498. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4499. sendStartTransactionRequest(gun_index);
  4500. refreshStartTimer(&clientTime.StartTransaction);
  4501. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4502. storeTempStopTransaction(gun_index);
  4503. }
  4504. //==========================================
  4505. // Charger stop transaction
  4506. //==========================================
  4507. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4508. {
  4509. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4510. sendStopTransactionRequest(gun_index);
  4511. OCPP_updatePeriodEnergy(gun_index);
  4512. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4513. refreshStartTimer(&clientTime.StopTransaction);
  4514. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4515. }
  4516. //==========================================
  4517. // Charger status report
  4518. //==========================================
  4519. //--- Check Mode Change ---//
  4520. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4521. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4522. {
  4523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4524. {
  4525. tempIndex = ((gun_index==2) ? 1: 0);
  4526. }
  4527. else
  4528. {
  4529. tempIndex = gun_index;
  4530. }
  4531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4532. {
  4533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4534. {
  4535. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4536. {
  4537. // Sent unplug message for California pricing logic
  4538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4539. {
  4540. uint8_t ts[36];
  4541. getNowDatetime(ts);
  4542. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4543. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4544. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4545. sendUnplugByDataTransferRequest(gun_index);
  4546. interLock.isSentUnplug[gun_index] = 1;
  4547. }
  4548. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4549. {
  4550. interLock.isSentUnplug[gun_index] = 0;
  4551. }
  4552. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4553. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4554. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4555. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4556. {
  4557. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4558. if((access(filenmae,F_OK))!=-1)
  4559. {
  4560. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4561. sprintf(str,"rm -f %s",filenmae);
  4562. system(str);
  4563. }
  4564. }
  4565. }
  4566. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4567. #if 1 // for TempStopTransaction
  4568. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4569. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4570. {
  4571. checkTempStopTransaction(gun_index);
  4572. }
  4573. #endif
  4574. }
  4575. }
  4576. }
  4577. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4578. {
  4579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4580. {
  4581. tempIndex = ((gun_index==2) ? 1: 0);
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. for (int index = 0; index < CCS_QUANTITY; index++)
  4588. {
  4589. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4590. {
  4591. 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]*/ )
  4592. {
  4593. // Sent unplug message for California pricing logic
  4594. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4595. {
  4596. uint8_t ts[36];
  4597. getNowDatetime(ts);
  4598. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4599. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4600. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4601. sendUnplugByDataTransferRequest(gun_index);
  4602. interLock.isSentUnplug[gun_index] = 1;
  4603. }
  4604. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4605. {
  4606. interLock.isSentUnplug[gun_index] = 0;
  4607. }
  4608. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4609. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4610. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4611. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4612. {
  4613. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4614. if((access(filenmae,F_OK))!=-1)
  4615. {
  4616. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4617. sprintf(str,"rm -f %s",filenmae);
  4618. system(str);
  4619. }
  4620. }
  4621. }
  4622. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4623. #if 1 // for TempStopTransaction
  4624. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4625. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4626. {
  4627. checkTempStopTransaction(gun_index);
  4628. }
  4629. #endif
  4630. }
  4631. }
  4632. }
  4633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4634. {
  4635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4636. {
  4637. tempIndex = ((gun_index==2) ? 1: 0);
  4638. }
  4639. else
  4640. {
  4641. tempIndex = gun_index;
  4642. }
  4643. for (int index = 0; index < GB_QUANTITY; index++)
  4644. {
  4645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4646. {
  4647. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4648. {
  4649. // Sent unplug message for California pricing logic
  4650. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4651. {
  4652. uint8_t ts[36];
  4653. getNowDatetime(ts);
  4654. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4655. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4656. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4657. sendUnplugByDataTransferRequest(gun_index);
  4658. interLock.isSentUnplug[gun_index] = 1;
  4659. }
  4660. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4661. {
  4662. interLock.isSentUnplug[gun_index] = 0;
  4663. }
  4664. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4665. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4666. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4667. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4668. {
  4669. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4670. if((access(filenmae,F_OK))!=-1)
  4671. {
  4672. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4673. sprintf(str,"rm -f %s",filenmae);
  4674. system(str);
  4675. }
  4676. }
  4677. }
  4678. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4679. #if 1 // for TempStopTransaction
  4680. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4681. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4682. {
  4683. checkTempStopTransaction(gun_index);
  4684. }
  4685. #endif
  4686. }
  4687. }
  4688. }
  4689. else if(gunType[gun_index] == GUN_TYPE_DO)
  4690. {
  4691. tempIndex = gun_index;
  4692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4693. {
  4694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4695. {
  4696. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4697. {
  4698. // Sent unplug message for California pricing logic
  4699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4700. {
  4701. uint8_t ts[36];
  4702. getNowDatetime(ts);
  4703. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4704. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4706. sendUnplugByDataTransferRequest(gun_index);
  4707. interLock.isSentUnplug[gun_index] = 1;
  4708. }
  4709. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4710. {
  4711. interLock.isSentUnplug[gun_index] = 0;
  4712. }
  4713. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4714. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4715. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4716. 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
  4717. {
  4718. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4719. if((access(filenmae,F_OK))!=-1)
  4720. {
  4721. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4722. sprintf(str,"rm -f %s",filenmae);
  4723. system(str);
  4724. }
  4725. }
  4726. }
  4727. 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);
  4728. #if 1 // for TempStopTransaction
  4729. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4730. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4731. {
  4732. checkTempStopTransaction(gun_index);
  4733. }
  4734. #endif
  4735. }
  4736. }
  4737. }
  4738. else
  4739. {
  4740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4741. {
  4742. tempIndex = 2;
  4743. }
  4744. else
  4745. {
  4746. tempIndex = gun_index;
  4747. }
  4748. for (int index = 0; index < AC_QUANTITY; index++)
  4749. {
  4750. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4751. {
  4752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4753. {
  4754. // Sent unplug message for California pricing logic
  4755. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4756. {
  4757. uint8_t ts[36];
  4758. getNowDatetime(ts);
  4759. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4760. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4761. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4762. sendUnplugByDataTransferRequest(gun_index);
  4763. interLock.isSentUnplug[gun_index] = 1;
  4764. }
  4765. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4766. {
  4767. interLock.isSentUnplug[gun_index] = 0;
  4768. }
  4769. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4770. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4771. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4772. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4773. {
  4774. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4775. if((access(filenmae,F_OK))!=-1)
  4776. {
  4777. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4778. sprintf(str,"rm -f %s",filenmae);
  4779. system(str);
  4780. }
  4781. }
  4782. }
  4783. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4784. #if 1 // for TempStopTransaction
  4785. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4786. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4787. {
  4788. checkTempStopTransaction(gun_index);
  4789. }
  4790. #endif
  4791. }
  4792. }// END
  4793. }
  4794. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4795. (
  4796. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4797. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4798. )
  4799. )
  4800. {
  4801. sendStatusNotificationRequest(gun_index);
  4802. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4803. }
  4804. //==============================================
  4805. // TCCI reader status report
  4806. //==============================================
  4807. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4808. {
  4809. reportReaderStatus(gun_index);
  4810. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4811. }
  4812. //==============================================
  4813. // CSU Trigger Smart Charging Profile
  4814. //==============================================
  4815. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4816. {
  4817. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4818. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4819. }
  4820. //==============================================
  4821. // Meter report
  4822. //==============================================
  4823. // Trigger MeterValue
  4824. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4825. {
  4826. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4827. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4828. }
  4829. // Clock-aligned Meter value
  4830. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4831. {
  4832. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4833. reqClockAlignMeter[gun_index] = 0;
  4834. }
  4835. // Sample period MeterValue
  4836. 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))))
  4837. {
  4838. //check Transaction active
  4839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4842. {
  4843. tempIndex = ((gun_index==2) ? 1: 0);
  4844. }
  4845. else
  4846. {
  4847. tempIndex = gun_index;
  4848. }
  4849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4850. {
  4851. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4852. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4853. {
  4854. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4855. {
  4856. reqSampleMeter[gun_index] = 1;
  4857. }
  4858. }
  4859. }// End for CHAdeMO
  4860. }
  4861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4864. {
  4865. tempIndex = ((gun_index==2) ? 1: 0);
  4866. }
  4867. else
  4868. {
  4869. tempIndex = gun_index;
  4870. }
  4871. for (int index = 0; index < CCS_QUANTITY; index++)
  4872. {
  4873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4874. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4875. {
  4876. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4877. {
  4878. reqSampleMeter[gun_index] = 1;
  4879. }
  4880. }
  4881. } // End for CCS
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < GB_QUANTITY; index++)
  4894. {
  4895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4896. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4899. {
  4900. reqSampleMeter[gun_index] = 1;
  4901. }
  4902. }
  4903. }// End for GB
  4904. }
  4905. else if(gunType[gun_index] == GUN_TYPE_DO)
  4906. {
  4907. tempIndex = gun_index;
  4908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4909. {
  4910. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4911. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4912. {
  4913. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4914. {
  4915. reqSampleMeter[gun_index] = 1;
  4916. }
  4917. }
  4918. }
  4919. }
  4920. else
  4921. {
  4922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4923. {
  4924. tempIndex = 2;
  4925. }
  4926. else
  4927. {
  4928. tempIndex = gun_index;
  4929. }
  4930. for (int index = 0; index < AC_QUANTITY; index++)
  4931. {
  4932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4933. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4934. {
  4935. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4936. {
  4937. reqSampleMeter[gun_index] = 1;
  4938. }
  4939. }
  4940. }//End for AC
  4941. }
  4942. if(reqSampleMeter[gun_index] == 1)
  4943. {
  4944. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4945. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4946. storeTempStopTransaction(gun_index);
  4947. reqSampleMeter[gun_index] = 0;
  4948. }
  4949. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4950. }
  4951. //==============================================
  4952. // Check Connector reserved
  4953. //==============================================
  4954. //===============================
  4955. // Check if Reserve is expired
  4956. //===============================
  4957. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4958. {
  4959. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4960. {
  4961. DEBUG_INFO("reserve expired.\n");
  4962. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4963. }
  4964. }//END OF Check if Reserve is expired
  4965. //==========================================
  4966. // csu trigger FirmwareStatusNotificationReq
  4967. //==========================================
  4968. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4969. {
  4970. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4971. }
  4972. //==========================================
  4973. // csu trigger DiagnosticsStatusNotificationReq
  4974. //==========================================
  4975. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4976. {
  4977. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4978. }
  4979. //==========================================
  4980. // csu trigger CancelReservationConf
  4981. //==========================================
  4982. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4983. {
  4984. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4985. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4986. }
  4987. //==========================================
  4988. // csu trigger ChangeAvailabilityConf
  4989. //==========================================
  4990. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4991. {
  4992. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4993. }
  4994. //==========================================
  4995. // csu trigger UnlockConnectorConf
  4996. //==========================================
  4997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4998. {
  4999. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5000. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5001. }
  5002. //==========================================
  5003. // csu trigger ReserveNowConf
  5004. //==========================================
  5005. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5006. {
  5007. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5008. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5009. }
  5010. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5011. {
  5012. sendSignCertificateRequest();
  5013. }
  5014. }
  5015. }
  5016. //==========================================
  5017. // send request routine
  5018. //==========================================
  5019. int sendAuthorizeRequest(int gun_index)
  5020. {
  5021. mtrace();
  5022. int result = FAIL;
  5023. char message[100]={0};
  5024. char guid[37];
  5025. char tempdata[65]={0};
  5026. DEBUG_INFO("sendAuthorizeRequest...\n");
  5027. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5028. //Local Authorize
  5029. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5030. {
  5031. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5032. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5033. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5034. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5035. result = PASS;
  5036. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5037. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5038. authorizeRetryTimes = 0;
  5039. return result;
  5040. }
  5041. 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))||
  5042. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5043. {
  5044. // Query from cache
  5045. DEBUG_INFO("Authorize from cache.\n");
  5046. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5047. // Query from list
  5048. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5049. {
  5050. DEBUG_INFO("Authorize from list.\n");
  5051. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5052. }
  5053. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5054. {
  5055. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5056. {
  5057. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5058. }
  5059. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5060. {
  5061. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5062. }
  5063. if(!GetOcppConnStatus())
  5064. {
  5065. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5066. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5067. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5068. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5069. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5070. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5071. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5072. authorizeRetryTimes = 0;
  5073. return result;
  5074. }
  5075. }
  5076. else
  5077. {
  5078. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5079. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5080. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5081. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5082. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5083. else
  5084. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5085. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5086. result = PASS;
  5087. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5088. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5089. authorizeRetryTimes = 0;
  5090. return result;
  5091. }
  5092. }
  5093. //initialize struct Authorize
  5094. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5095. //get data from shared memory
  5096. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5097. random_uuid(guid);
  5098. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5099. LWS_Send(message);
  5100. sprintf(tempdata, "Authorize,%d", gun_index);
  5101. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5102. {
  5103. result = PASS;
  5104. DEBUG_INFO("Authorize mapItem pass\n");
  5105. }
  5106. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5107. return result;
  5108. }
  5109. int sendBootNotificationRequest(void)
  5110. {
  5111. mtrace();
  5112. int result = FAIL;
  5113. char message[500]={0}, payload[700]={0};
  5114. char guid[37]={0};
  5115. char tempdata[65]={0};
  5116. // Fill BootNotification fields
  5117. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5118. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5119. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5120. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5121. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5122. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5123. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5124. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5125. ShmOCPP16Data->ChargeBoxId
  5126. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5127. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5128. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5129. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5130. ,ShmOCPP16Data->BootNotification.CpIccid
  5131. ,ShmOCPP16Data->BootNotification.CpImsi);
  5132. random_uuid(guid);
  5133. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5134. LWS_Send(message);
  5135. sprintf(tempdata, "BootNotification,0");
  5136. 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*/)
  5137. {
  5138. result = PASS;
  5139. }
  5140. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5141. strcpy(queuedata,message);
  5142. return result;
  5143. }
  5144. int sendDataTransferRequest(int gun_index)
  5145. {
  5146. mtrace();
  5147. char message[1000]={0};
  5148. char guid[37]={0};
  5149. char tempdata[65]={0};
  5150. int result = FAIL;
  5151. random_uuid(guid);
  5152. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5153. MESSAGE_TYPE_CALL,
  5154. guid,
  5155. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5156. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5157. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5158. LWS_Send(message);
  5159. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5160. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5161. {
  5162. result = PASS;
  5163. DEBUG_INFO("DataTransfer mapItem pass\n");
  5164. }
  5165. return result;
  5166. }
  5167. int sendUnplugByDataTransferRequest(int gun_index)
  5168. {
  5169. mtrace();
  5170. char message[1000]={0};
  5171. char guid[37]={0};
  5172. char tempdata[65]={0};
  5173. int result = FAIL;
  5174. random_uuid(guid);
  5175. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5176. (gun_index+1),
  5177. MESSAGE_TYPE_CALL,
  5178. guid,
  5179. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5180. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5181. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5182. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5183. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5184. {
  5185. result = PASS;
  5186. DEBUG_INFO("DataTransfer mapItem pass\n");
  5187. }
  5188. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5189. return result;
  5190. }
  5191. int sendDiagnosticsStatusNotificationRequest(char *status)
  5192. {
  5193. mtrace();
  5194. int result = FAIL;
  5195. char message[110]={0};
  5196. char guid[37]={0};
  5197. char tempdata[65]={0};
  5198. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5199. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5200. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5201. random_uuid(guid);
  5202. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5203. LWS_SendNow(message);
  5204. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5206. {
  5207. result = PASS;
  5208. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5209. }
  5210. //#ifdef SystemLogMessage
  5211. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5212. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5213. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5214. //#endif
  5215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5216. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5217. //record status
  5218. if(strcmp(status,"Idle")==0)
  5219. {
  5220. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5221. }
  5222. else if(strcmp(status,"Uploaded")==0)
  5223. {
  5224. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5225. }
  5226. else if(strcmp(status,"UploadFailed")==0)
  5227. {
  5228. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5229. }
  5230. else if(strcmp(status,"Uploading")==0)
  5231. {
  5232. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5233. }
  5234. return result;
  5235. }
  5236. int sendFirmwareStatusNotificationRequest(char *status)
  5237. {
  5238. mtrace();
  5239. int result = FAIL;
  5240. char message[110]={0};
  5241. char guid[37]={0};
  5242. char tempdata[65]={0};
  5243. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5244. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5245. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5246. random_uuid(guid);
  5247. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5248. LWS_SendNow(message);
  5249. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5250. 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*/)
  5251. {
  5252. result = PASS;
  5253. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5254. }
  5255. //#ifdef SystemLogMessage
  5256. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5257. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5258. //#endif
  5259. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5260. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5261. //record status
  5262. if(strcmp(status,"Downloaded")==0)
  5263. {
  5264. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5265. }
  5266. else if(strcmp(status,"DownloadFailed")==0)
  5267. {
  5268. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5269. }
  5270. else if(strcmp(status,"Downloading")==0)
  5271. {
  5272. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5273. }
  5274. else if(strcmp(status,"Idle")==0)
  5275. {
  5276. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5277. }
  5278. else if(strcmp(status,"InstallationFailed")==0)
  5279. {
  5280. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5281. }
  5282. else if(strcmp(status,"Installing")==0)
  5283. {
  5284. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5285. }
  5286. else if(strcmp(status,"Installed")==0)
  5287. {
  5288. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5289. }
  5290. return result;
  5291. }
  5292. int sendHeartbeatRequest(int gun_index)
  5293. {
  5294. mtrace();
  5295. int result = FAIL;
  5296. char message[80]={0};
  5297. char guid[37]={0};
  5298. char tempdata[65]={0};
  5299. random_uuid(guid);
  5300. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5301. , MESSAGE_TYPE_CALL
  5302. , guid );
  5303. LWS_Send(message);
  5304. sprintf(tempdata, "Heartbeat,%d", 0);
  5305. 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*/)
  5306. {
  5307. result = PASS;
  5308. }
  5309. return result;
  5310. }
  5311. int sendStartTransactionRequest(int gun_index)
  5312. {
  5313. mtrace();
  5314. int result = FAIL;
  5315. char message[250]={0};
  5316. char guid[37]={0};
  5317. struct timeval tmnow;
  5318. struct tm *tm;
  5319. char buf[28];//, usec_buf[6];
  5320. char tempdata[65]={0};
  5321. int tempIndex = 0;
  5322. DEBUG_INFO("sendStartTransactionRequest...\n");
  5323. gettimeofday(&tmnow, NULL);
  5324. time_t t;
  5325. t = time(NULL);
  5326. /*UTC time and date*/
  5327. tm = gmtime(&t);
  5328. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5329. #if 0 // remove temporally
  5330. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5331. strcat(buf,".");
  5332. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5333. strcat(buf,usec_buf);
  5334. #endif
  5335. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5336. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5337. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5338. // clear StartTransaction Response
  5339. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5340. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5341. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5342. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5343. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5345. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5346. {
  5347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5348. {
  5349. tempIndex = ((gun_index==2) ? 1: 0);
  5350. }
  5351. else
  5352. {
  5353. tempIndex = gun_index;
  5354. }
  5355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5358. {
  5359. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5360. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5361. }
  5362. }
  5363. }
  5364. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5365. {
  5366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5367. {
  5368. tempIndex = ((gun_index==2) ? 1: 0);
  5369. }
  5370. else
  5371. {
  5372. tempIndex = gun_index;
  5373. }
  5374. for (int index = 0; index < CCS_QUANTITY; index++)
  5375. {
  5376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5377. {
  5378. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5379. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5380. }
  5381. }
  5382. }
  5383. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5384. {
  5385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5386. {
  5387. tempIndex = ((gun_index==2) ? 1: 0);
  5388. }
  5389. else
  5390. {
  5391. tempIndex = gun_index;
  5392. }
  5393. for (int index = 0; index < GB_QUANTITY; index++)
  5394. {
  5395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5396. {
  5397. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5398. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5399. }
  5400. }
  5401. }
  5402. else if(gunType[gun_index] == GUN_TYPE_DO)
  5403. {
  5404. tempIndex = gun_index;
  5405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5406. {
  5407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5408. {
  5409. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5410. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5411. }
  5412. }
  5413. }
  5414. else
  5415. {
  5416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5417. {
  5418. tempIndex = 2;
  5419. }
  5420. else
  5421. {
  5422. tempIndex = gun_index;
  5423. }
  5424. for (int index = 0; index < AC_QUANTITY; index++)
  5425. {
  5426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5427. {
  5428. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5429. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5430. }
  5431. }
  5432. }
  5433. random_uuid(guid);
  5434. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5435. {
  5436. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5437. , gun_index +1
  5438. , MESSAGE_TYPE_CALL
  5439. , guid
  5440. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5441. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5442. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5443. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5444. }
  5445. else
  5446. {
  5447. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5448. , gun_index +1
  5449. , MESSAGE_TYPE_CALL
  5450. , guid
  5451. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5452. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5453. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5454. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5455. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5456. }
  5457. #if 1
  5458. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5459. 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*/)
  5460. {
  5461. result = PASS;
  5462. }
  5463. #endif
  5464. strcpy(queuedata, message);
  5465. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5466. OCPP_insert_transaction_msg(YES, queuedata);
  5467. return result;
  5468. }
  5469. int sendStatusNotificationRequest(int gun_index)
  5470. {
  5471. mtrace();
  5472. int result = FAIL;
  5473. char message[600]={0};
  5474. char guid[37];
  5475. int currentStatus = 0;
  5476. struct timeval tmnow;
  5477. struct tm *tm;
  5478. char buf[28];//, usec_buf[6];
  5479. char tempdata[65]={0};
  5480. int tempIndex = 0;
  5481. uint8_t isStateChanged = TRUE;
  5482. uint8_t isContentIllegal = TRUE;
  5483. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5484. gettimeofday(&tmnow, NULL);
  5485. time_t t;
  5486. t = time(NULL);
  5487. /*UTC time and date*/
  5488. tm = gmtime(&t);
  5489. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5490. #if 0 // remove temporally
  5491. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5492. strcat(buf,".");
  5493. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5494. strcat(buf,usec_buf);
  5495. #endif
  5496. //printf("%s",buf);
  5497. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5498. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5499. // it's option
  5500. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5501. /*
  5502. enum _SYSTEM_STATUS
  5503. {
  5504. S_BOOTING = 0,
  5505. S_IDLE, = 1
  5506. S_AUTHORIZING, =2
  5507. S_REASSIGN_CHECK, =3
  5508. S_REASSIGN, =4
  5509. S_PRECHARGE, =5
  5510. S_PREPARING_FOR_EV, =6
  5511. S_PREPARING_FOR_EVSE, =7
  5512. S_CHARGING, =8
  5513. S_TERMINATING, =9
  5514. S_COMPLETE, =10
  5515. S_ALARM, =11
  5516. S_FAULT =12
  5517. }
  5518. */
  5519. //check Transaction active
  5520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5521. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5522. {
  5523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5524. {
  5525. tempIndex = ((gun_index==2) ? 1: 0);
  5526. }
  5527. else
  5528. {
  5529. tempIndex = gun_index;
  5530. }
  5531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5532. {
  5533. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5534. {
  5535. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5536. {
  5537. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5538. {
  5539. currentStatus = Preparing; //OCPP Status: Preparing
  5540. }
  5541. else
  5542. {
  5543. currentStatus = Available; //OCPP Status: Available
  5544. }
  5545. }
  5546. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5547. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5548. ) //S_PRECHARGE
  5549. {
  5550. currentStatus = Preparing; //OCPP Status: Preparing
  5551. }
  5552. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5553. {
  5554. currentStatus = Charging; //OCPP Status: Charging
  5555. }
  5556. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5557. {
  5558. currentStatus = Finishing; //OCPP Status: Finishing
  5559. }
  5560. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5561. {
  5562. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5563. }
  5564. 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
  5565. {
  5566. currentStatus = Unavailable; //OCPP Status: Unavailable
  5567. }
  5568. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5569. {
  5570. currentStatus = Faulted; //OCPP Status: Faulted
  5571. }
  5572. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5573. {
  5574. currentStatus = Reserved; //OCPP Status: Reserved
  5575. }
  5576. } //end of the same index
  5577. }//end of for CHAdeMO_QUANTITY
  5578. }
  5579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5580. {
  5581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5582. {
  5583. tempIndex = ((gun_index==2) ? 1: 0);
  5584. }
  5585. else
  5586. {
  5587. tempIndex = gun_index;
  5588. }
  5589. for (int index = 0; index < CCS_QUANTITY; index++)
  5590. {
  5591. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5594. {
  5595. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5596. {
  5597. currentStatus = Preparing; //OCPP Status: Preparing
  5598. }
  5599. else
  5600. {
  5601. currentStatus = Available; //OCPP Status: Available
  5602. }
  5603. }
  5604. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5605. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5606. ) //S_PRECHARGE
  5607. {
  5608. currentStatus = Preparing; //OCPP Status: Preparing
  5609. }
  5610. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5611. {
  5612. currentStatus = Charging; //OCPP Status: Charging
  5613. }
  5614. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5615. {
  5616. currentStatus = Finishing; //OCPP Status: Finishing
  5617. }
  5618. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5619. {
  5620. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5621. }
  5622. 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
  5623. {
  5624. currentStatus = Unavailable; //OCPP Status : Unavailable
  5625. }
  5626. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5627. {
  5628. currentStatus = Faulted; //OCPP Status: Faulted
  5629. }
  5630. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5631. {
  5632. currentStatus = Reserved; //OCPP Status: Reserved
  5633. }
  5634. } //end of the same index
  5635. } // end of for CCS_QUANTITY
  5636. }
  5637. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5638. {
  5639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5640. {
  5641. tempIndex = ((gun_index==2) ? 1: 0);
  5642. }
  5643. else
  5644. {
  5645. tempIndex = gun_index;
  5646. }
  5647. for (int index = 0; index < GB_QUANTITY; index++)
  5648. {
  5649. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5650. {
  5651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5652. {
  5653. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5654. {
  5655. currentStatus = Preparing; //OCPP Status: Preparing
  5656. }
  5657. else
  5658. {
  5659. currentStatus = Available; //OCPP Status: Available
  5660. }
  5661. }
  5662. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5663. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5664. ) //S_PRECHARGE
  5665. {
  5666. currentStatus = Preparing; //OCPP Status: Preparing
  5667. }
  5668. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5669. {
  5670. currentStatus = Charging; //OCPP Status: Charging
  5671. }
  5672. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5673. {
  5674. currentStatus = Finishing; //OCPP Status: Finishing
  5675. }
  5676. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5677. {
  5678. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5679. }
  5680. 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
  5681. {
  5682. currentStatus = Unavailable; //OCPP Status: Unavailable
  5683. }
  5684. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5685. {
  5686. currentStatus = Faulted; //OCPP Status: Faulted
  5687. }
  5688. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5689. {
  5690. currentStatus = Reserved; //OCPP Status: Reserved
  5691. }
  5692. } //end of the same index
  5693. } // end of for GB_QUANTITY
  5694. }
  5695. else if(gunType[gun_index] == GUN_TYPE_DO)
  5696. {
  5697. tempIndex = gun_index;
  5698. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5699. {
  5700. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5703. {
  5704. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5705. {
  5706. currentStatus = Preparing; //OCPP Status: Preparing
  5707. }
  5708. else
  5709. {
  5710. currentStatus = Available; //OCPP Status: Available
  5711. }
  5712. }
  5713. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5714. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5715. ) //S_PRECHARGE
  5716. {
  5717. currentStatus = Preparing; //OCPP Status: Preparing
  5718. }
  5719. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5720. {
  5721. currentStatus = Charging; //OCPP Status: Charging
  5722. }
  5723. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5724. {
  5725. currentStatus = Finishing; //OCPP Status: Finishing
  5726. }
  5727. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5728. {
  5729. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5730. }
  5731. 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
  5732. {
  5733. currentStatus = Unavailable; //OCPP Status: Unavailable
  5734. }
  5735. 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
  5736. {
  5737. currentStatus = Faulted; //OCPP Status: Faulted
  5738. }
  5739. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5740. {
  5741. currentStatus = Reserved; //OCPP Status: Reserved
  5742. }
  5743. } //end of the same index
  5744. }
  5745. }
  5746. else
  5747. {
  5748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5749. {
  5750. tempIndex = 2;
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. for (int index = 0; index < AC_QUANTITY; index++)
  5757. {
  5758. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5761. {
  5762. 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))
  5763. {
  5764. currentStatus = Preparing; //OCPP Status: Preparing
  5765. }
  5766. else
  5767. {
  5768. currentStatus = Available; //OCPP Status: Available
  5769. }
  5770. }
  5771. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5772. {
  5773. currentStatus = Preparing; //OCPP Status: Preparing
  5774. }
  5775. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5776. {
  5777. currentStatus = Charging; //OCPP Status: Charging
  5778. }
  5779. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5780. {
  5781. currentStatus = Finishing; //OCPP Status: Finishing
  5782. }
  5783. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5784. {
  5785. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5786. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5787. else
  5788. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5789. }
  5790. 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
  5791. {
  5792. currentStatus = Unavailable; //OCPP Status: Unavailable
  5793. }
  5794. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5795. {
  5796. currentStatus = Faulted; //OCPP Status: Faulted
  5797. }
  5798. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5799. {
  5800. currentStatus = Reserved; //OCPP Status: Reserved
  5801. }
  5802. }//end of the same index
  5803. }//end of for AC_QUANTITY
  5804. }
  5805. //it's option
  5806. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5807. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5808. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5809. {
  5810. isStateChanged = FALSE;
  5811. }
  5812. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5813. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5814. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5815. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5816. isContentIllegal = TRUE;
  5817. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5818. {
  5819. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5820. {
  5821. isContentIllegal = FALSE;
  5822. break;
  5823. }
  5824. }
  5825. if(isContentIllegal)
  5826. {
  5827. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5828. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5829. }
  5830. random_uuid(guid);
  5831. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5832. , MESSAGE_TYPE_CALL
  5833. , guid
  5834. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5835. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5836. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5837. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5838. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5839. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5840. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5841. if((server_sign == TRUE) && isStateChanged)
  5842. {
  5843. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5844. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5845. LWS_Send(message);
  5846. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5847. 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*/)
  5848. {
  5849. //DEBUG_ERROR("statusNotification mapitem pass");
  5850. result = PASS;
  5851. }
  5852. }
  5853. else
  5854. {
  5855. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5856. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5857. result = PASS;
  5858. }
  5859. return result;
  5860. }
  5861. int sendStopTransactionRequest(int gun_index)
  5862. {
  5863. mtrace();
  5864. int result = FAIL;
  5865. //char message[1500]={0};
  5866. char guid[37]={0};
  5867. char tempdata[65]={0};
  5868. int tempIndex = 0;
  5869. char TempStopTransaction[256];
  5870. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5871. //int idx_sample=0;
  5872. DEBUG_INFO("sendStopTransactionRequest \n");
  5873. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5874. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5875. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5876. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5877. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5878. {
  5879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5880. {
  5881. tempIndex = ((gun_index==2) ? 1: 0);
  5882. }
  5883. else
  5884. {
  5885. tempIndex = gun_index;
  5886. }
  5887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5890. {
  5891. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5892. }
  5893. }// END OF CHAdeMO_QUANTITY
  5894. }
  5895. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5898. {
  5899. tempIndex = ((gun_index==2) ? 1: 0);
  5900. }
  5901. else
  5902. {
  5903. tempIndex = gun_index;
  5904. }
  5905. for (int index = 0; index < CCS_QUANTITY; index++)
  5906. {
  5907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5908. {
  5909. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5910. }
  5911. }// END OF CCS_QUANTITY
  5912. }
  5913. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5914. {
  5915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5916. {
  5917. tempIndex = ((gun_index==2) ? 1: 0);
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. for (int index = 0; index < GB_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5926. {
  5927. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5928. }
  5929. }// END OF GB_QUANTITY
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_DO)
  5932. {
  5933. tempIndex = gun_index;
  5934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5935. {
  5936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5937. {
  5938. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5939. }
  5940. }// END OF GB_QUANTITY
  5941. }
  5942. else
  5943. {
  5944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5945. {
  5946. tempIndex = 2;
  5947. }
  5948. else
  5949. {
  5950. tempIndex = gun_index;
  5951. }
  5952. for (int index = 0; index < AC_QUANTITY; index++)
  5953. {
  5954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5955. {
  5956. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5957. }
  5958. }// END OF AC_QUANTITY
  5959. }
  5960. //====================================== Stop Transaction Time =====================================================
  5961. struct timeval tmnow;
  5962. struct tm *tm;
  5963. char buf[28];//, usec_buf[6];
  5964. gettimeofday(&tmnow, NULL);
  5965. time_t t;
  5966. t = time(NULL);
  5967. /*UTC time and date*/
  5968. tm = gmtime(&t);
  5969. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5971. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5972. random_uuid(guid);
  5973. /***********************************transactionData******************************************************/
  5974. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5976. //=================================
  5977. // Transaction_Begin
  5978. //=================================
  5979. //=================================
  5980. // Transaction_End
  5981. //=================================
  5982. // ================================= Current.Import L1 ===============================================
  5983. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5984. {
  5985. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5986. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5987. {
  5988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5989. {
  5990. tempIndex = ((gun_index==2) ? 1: 0);
  5991. }
  5992. else
  5993. {
  5994. tempIndex = gun_index;
  5995. }
  5996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5997. {
  5998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5999. {
  6000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6001. }
  6002. }// End of for CHAdeMO_QUANTITY
  6003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6004. }
  6005. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6006. {
  6007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6008. {
  6009. tempIndex = ((gun_index==2) ? 1: 0);
  6010. }
  6011. else
  6012. {
  6013. tempIndex = gun_index;
  6014. }
  6015. for (int index = 0; index < CCS_QUANTITY; index++)
  6016. {
  6017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6018. {
  6019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6020. }
  6021. }// End of for CCS_QUANTITY
  6022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6023. }
  6024. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6025. {
  6026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6027. {
  6028. tempIndex = ((gun_index==2) ? 1: 0);
  6029. }
  6030. else
  6031. {
  6032. tempIndex = gun_index;
  6033. }
  6034. for (int index = 0; index < GB_QUANTITY; index++)
  6035. {
  6036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6037. {
  6038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6039. }
  6040. }// End of for GB_QUANTITY
  6041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6042. }
  6043. else if(gunType[gun_index] == GUN_TYPE_DO)
  6044. {
  6045. tempIndex = gun_index;
  6046. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6047. {
  6048. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6049. {
  6050. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6051. }
  6052. }
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6054. }
  6055. else
  6056. {
  6057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6058. {
  6059. tempIndex = 2;
  6060. }
  6061. else
  6062. {
  6063. tempIndex = gun_index;
  6064. }
  6065. for (int index = 0; index < AC_QUANTITY; index++)
  6066. {
  6067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6068. {
  6069. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6070. }
  6071. }// End of for AC_QUANTITY
  6072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6073. }
  6074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6079. }
  6080. // ================================= Energy.Active.Import.Interval ==============================================
  6081. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6082. {
  6083. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6084. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6085. {
  6086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6087. {
  6088. tempIndex = ((gun_index==2) ? 1: 0);
  6089. }
  6090. else
  6091. {
  6092. tempIndex = gun_index;
  6093. }
  6094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6095. {
  6096. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6097. {
  6098. 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
  6099. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6100. }
  6101. }// END OF CHAdeMO_QUANTITY
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6103. }
  6104. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6105. {
  6106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6107. {
  6108. tempIndex = ((gun_index==2) ? 1: 0);
  6109. }
  6110. else
  6111. {
  6112. tempIndex = gun_index;
  6113. }
  6114. for (int index = 0; index < CCS_QUANTITY; index++)
  6115. {
  6116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6117. {
  6118. 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
  6119. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6120. }
  6121. }// END OF CCS_QUANTITY
  6122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6123. }
  6124. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6125. {
  6126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6127. {
  6128. tempIndex = ((gun_index==2) ? 1: 0);
  6129. }
  6130. else
  6131. {
  6132. tempIndex = gun_index;
  6133. }
  6134. for (int index = 0; index < GB_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6137. {
  6138. 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
  6139. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6140. }
  6141. }// END OF GB_QUANTITY
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6143. }
  6144. else if(gunType[gun_index] == GUN_TYPE_DO)
  6145. {
  6146. tempIndex = gun_index;
  6147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6148. {
  6149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6150. {
  6151. 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
  6152. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6153. }
  6154. }
  6155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6156. }
  6157. else
  6158. {
  6159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6160. {
  6161. tempIndex = 2;
  6162. }
  6163. else
  6164. {
  6165. tempIndex = gun_index;
  6166. }
  6167. for (int index = 0; index < AC_QUANTITY; index++)
  6168. {
  6169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6170. {
  6171. 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
  6172. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6173. }
  6174. }// END OF AC_QUANTITY
  6175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6176. }
  6177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6182. }
  6183. //=================================== Power.Active.Import ==================================================
  6184. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6185. {
  6186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6190. {
  6191. tempIndex = ((gun_index==2) ? 1: 0);
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6200. {
  6201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6202. }
  6203. } // End for CHAdeMO_QUANTITY
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6205. }
  6206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6207. {
  6208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6209. {
  6210. tempIndex = ((gun_index==2) ? 1: 0);
  6211. }
  6212. else
  6213. {
  6214. tempIndex = gun_index;
  6215. }
  6216. for (int index = 0; index < CCS_QUANTITY; index++)
  6217. {
  6218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6219. {
  6220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6221. }
  6222. } // END for CCS_QUANTITY
  6223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6224. }
  6225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6226. {
  6227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6228. {
  6229. tempIndex = ((gun_index==2) ? 1: 0);
  6230. }
  6231. else
  6232. {
  6233. tempIndex = gun_index;
  6234. }
  6235. for (int index = 0; index < GB_QUANTITY; index++)
  6236. {
  6237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6238. {
  6239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6240. }
  6241. }// END for GB_QUANTITY
  6242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6243. }
  6244. else if(gunType[gun_index] == GUN_TYPE_DO)
  6245. {
  6246. tempIndex = gun_index;
  6247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6248. {
  6249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6250. {
  6251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6252. }
  6253. }
  6254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6255. }
  6256. else
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6259. {
  6260. tempIndex = 2;
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < AC_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6269. {
  6270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6271. }
  6272. } // END for AC_QUANTITY
  6273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6274. }
  6275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6280. }
  6281. //============================ Voltage L1 ====================================
  6282. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6283. {
  6284. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6285. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6286. {
  6287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6288. {
  6289. tempIndex = ((gun_index==2) ? 1: 0);
  6290. }
  6291. else
  6292. {
  6293. tempIndex = gun_index;
  6294. }
  6295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6296. {
  6297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6298. {
  6299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6300. }
  6301. } // END OF FOR CHAdeMO_QUANTITY
  6302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6303. }
  6304. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6305. {
  6306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6307. {
  6308. tempIndex = ((gun_index==2) ? 1: 0);
  6309. }
  6310. else
  6311. {
  6312. tempIndex = gun_index;
  6313. }
  6314. for (int index = 0; index < CCS_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6317. {
  6318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6319. }
  6320. } // END OF FOR CCS_QUANTITY
  6321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6322. }
  6323. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6324. {
  6325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6326. {
  6327. tempIndex = ((gun_index==2) ? 1: 0);
  6328. }
  6329. else
  6330. {
  6331. tempIndex = gun_index;
  6332. }
  6333. for (int index = 0; index < GB_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6336. {
  6337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6338. }
  6339. } // END OF FOR GB_QUANTITY
  6340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6341. }
  6342. else if(gunType[gun_index] == GUN_TYPE_DO)
  6343. {
  6344. tempIndex = gun_index;
  6345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6353. }
  6354. else
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6357. {
  6358. tempIndex = 2;
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < AC_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6367. {
  6368. 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
  6369. }
  6370. } // END OF FOR AC_QUANTITY
  6371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6372. }
  6373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6378. }
  6379. //====================== End SoC ================================
  6380. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6381. {
  6382. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6383. 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))
  6384. {
  6385. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6386. {
  6387. tempIndex = ((gun_index==2) ? 1: 0);
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6394. {
  6395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6398. {
  6399. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6400. }
  6401. }
  6402. }
  6403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6404. {
  6405. for (int index = 0; index < CCS_QUANTITY; index++)
  6406. {
  6407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6408. {
  6409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6410. }
  6411. }
  6412. }
  6413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6414. {
  6415. for (int index = 0; index < GB_QUANTITY; index++)
  6416. {
  6417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6418. {
  6419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6420. }
  6421. }
  6422. }
  6423. else if(gunType[gun_index] == GUN_TYPE_DO)
  6424. {
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6430. }
  6431. }
  6432. }
  6433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6439. } // END FOR DC CASE
  6440. }
  6441. // ================================= Current.Import L2 ===============================================
  6442. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6443. {
  6444. // AC 3 phse L2 current
  6445. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6446. {
  6447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6448. {
  6449. tempIndex = 2;
  6450. }
  6451. else
  6452. {
  6453. tempIndex = gun_index;
  6454. }
  6455. for (int index = 0; index < AC_QUANTITY; index++)
  6456. {
  6457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6458. {
  6459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6460. }
  6461. }// End of for AC_QUANTITY
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6463. }
  6464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6469. }
  6470. // ================================= Current.Import L3 ===============================================
  6471. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6472. {
  6473. // AC 3 phse L3 current
  6474. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6475. {
  6476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6477. {
  6478. tempIndex = 2;
  6479. }
  6480. else
  6481. {
  6482. tempIndex = gun_index;
  6483. }
  6484. for (int index = 0; index < AC_QUANTITY; index++)
  6485. {
  6486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6487. {
  6488. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6489. }
  6490. }// End of for AC_QUANTITY
  6491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6492. }
  6493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6498. }
  6499. //============================ Voltage L2 ====================================
  6500. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6501. {
  6502. // AC 3 phse L2 voltage
  6503. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6504. {
  6505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6506. {
  6507. tempIndex = 2;
  6508. }
  6509. else
  6510. {
  6511. tempIndex = gun_index;
  6512. }
  6513. for (int index = 0; index < AC_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6516. {
  6517. 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
  6518. }
  6519. } // END OF FOR AC_QUANTITY
  6520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6521. }
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6527. }
  6528. //============================ Voltage L3 ====================================
  6529. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6530. {
  6531. // AC 3 phse L3 voltage
  6532. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6533. {
  6534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6535. {
  6536. tempIndex = 2;
  6537. }
  6538. else
  6539. {
  6540. tempIndex = gun_index;
  6541. }
  6542. for (int index = 0; index < AC_QUANTITY; index++)
  6543. {
  6544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6545. {
  6546. 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
  6547. }
  6548. } // END OF FOR AC_QUANTITY
  6549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6550. }
  6551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6556. }
  6557. //====================== Start SoC ================================
  6558. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6559. {
  6560. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6561. 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))
  6562. {
  6563. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6564. {
  6565. tempIndex = ((gun_index==2) ? 1: 0);
  6566. }
  6567. else
  6568. {
  6569. tempIndex = gun_index;
  6570. }
  6571. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6572. {
  6573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6578. }
  6579. }
  6580. }
  6581. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6582. {
  6583. for (int index = 0; index < CCS_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6588. }
  6589. }
  6590. }
  6591. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6592. {
  6593. for (int index = 0; index < GB_QUANTITY; index++)
  6594. {
  6595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6596. {
  6597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6598. }
  6599. }
  6600. }
  6601. else if(gunType[gun_index] == GUN_TYPE_DO)
  6602. {
  6603. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6604. {
  6605. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6606. {
  6607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6608. }
  6609. }
  6610. }
  6611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6617. } // END FOR DC CASE
  6618. }
  6619. //================================================ Message create ====================================================
  6620. json_object *StopTransaction = json_object_new_object();
  6621. json_object *transactionDatas = json_object_new_array();
  6622. json_object *sampledValues = json_object_new_array();
  6623. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6624. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6625. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6626. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6627. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6628. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6629. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6630. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6631. {
  6632. json_object *transactionData = json_object_new_object();
  6633. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6634. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6635. {
  6636. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6637. {
  6638. json_object *sampledValue = json_object_new_object();
  6639. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6640. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6641. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6642. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6643. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6644. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6645. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6646. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6647. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6648. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6649. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6650. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6651. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6652. json_object_array_add(sampledValues, sampledValue);
  6653. }
  6654. }
  6655. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6656. json_object_array_add(transactionDatas, transactionData);
  6657. }
  6658. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6659. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6660. ,MESSAGE_TYPE_CALL
  6661. ,guid
  6662. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6663. json_object_put(StopTransaction);
  6664. #if 1 // for TempStopTransaction
  6665. //Delete TempStopTransaction
  6666. if((access(TempStopTransaction,F_OK))!=-1)
  6667. {
  6668. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6669. }
  6670. #endif
  6671. #if 1
  6672. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6673. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6674. {
  6675. result = PASS;
  6676. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6677. }
  6678. #endif
  6679. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6680. OCPP_insert_transaction_msg(NO, queuedata);
  6681. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6682. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6683. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6684. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6685. {
  6686. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6687. }
  6688. //for test
  6689. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6690. return result;
  6691. }
  6692. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6693. {
  6694. mtrace();
  6695. int result = FAIL;
  6696. char guid[37]={0};
  6697. char tempdata[65]={0};
  6698. int tempIndex = 0;
  6699. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6700. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6701. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6702. //set value
  6703. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6704. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6705. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6706. -1);
  6707. random_uuid(guid);
  6708. //UTC Date time
  6709. struct timeval tmnow;
  6710. struct tm *tm;
  6711. char buf[28];//, usec_buf[6];
  6712. gettimeofday(&tmnow, NULL);
  6713. time_t t;
  6714. t = time(NULL);
  6715. /*UTC time and date*/
  6716. tm = gmtime(&t);
  6717. if(dataType == ReadingContext_Sample_Clock)
  6718. {
  6719. struct tm *tmTarget;
  6720. struct timeb tbTarget;
  6721. tbTarget.time = mktime(tm);
  6722. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6723. tmTarget = gmtime(&tbTarget.time);
  6724. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6725. }
  6726. else
  6727. {
  6728. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6729. }
  6730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6731. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6732. //********************************(1)Current.Import L1************************************************/
  6733. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6734. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6735. (dataType == ReadingContext_Trigger))
  6736. {
  6737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6738. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6739. {
  6740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6741. {
  6742. tempIndex = ((gun_index==2) ? 1: 0);
  6743. }
  6744. else
  6745. {
  6746. tempIndex = gun_index;
  6747. }
  6748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6749. {
  6750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6751. {
  6752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6753. }
  6754. }
  6755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6756. }
  6757. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6758. {
  6759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6760. {
  6761. tempIndex = ((gun_index==2) ? 1: 0);
  6762. }
  6763. else
  6764. {
  6765. tempIndex = gun_index;
  6766. }
  6767. for (int index = 0; index < CCS_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6770. {
  6771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6772. }
  6773. }
  6774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6775. }
  6776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6777. {
  6778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6779. {
  6780. tempIndex = ((gun_index==2) ? 1: 0);
  6781. }
  6782. else
  6783. {
  6784. tempIndex = gun_index;
  6785. }
  6786. for (int index = 0; index < GB_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6789. {
  6790. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6791. }
  6792. }
  6793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6794. }
  6795. else if(gunType[gun_index] == GUN_TYPE_DO)
  6796. {
  6797. tempIndex = gun_index;
  6798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6799. {
  6800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6801. {
  6802. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6803. }
  6804. }
  6805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6806. }
  6807. else
  6808. {
  6809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6810. {
  6811. tempIndex = 2;
  6812. }
  6813. else
  6814. {
  6815. tempIndex = gun_index;
  6816. }
  6817. for (int index = 0; index < AC_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6820. {
  6821. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6822. }
  6823. }
  6824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6825. }
  6826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6831. }
  6832. //********************************(2)Energy.Active.Import.Register ************************************************/
  6833. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6834. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6835. (dataType == ReadingContext_Trigger))
  6836. {
  6837. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6838. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6839. {
  6840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6841. {
  6842. tempIndex = ((gun_index==2) ? 1: 0);
  6843. }
  6844. else
  6845. {
  6846. tempIndex = gun_index;
  6847. }
  6848. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6849. {
  6850. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6851. {
  6852. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6853. }
  6854. }
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6856. }
  6857. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6858. {
  6859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6860. {
  6861. tempIndex = ((gun_index==2) ? 1: 0);
  6862. }
  6863. else
  6864. {
  6865. tempIndex = gun_index;
  6866. }
  6867. for (int index = 0; index < CCS_QUANTITY; index++)
  6868. {
  6869. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6870. {
  6871. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6872. }
  6873. }
  6874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6875. }
  6876. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6877. {
  6878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6879. {
  6880. tempIndex = ((gun_index==2) ? 1: 0);
  6881. }
  6882. else
  6883. {
  6884. tempIndex = gun_index;
  6885. }
  6886. for (int index = 0; index < GB_QUANTITY; index++)
  6887. {
  6888. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6889. {
  6890. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6891. }
  6892. }
  6893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6894. }
  6895. else if(gunType[gun_index] == GUN_TYPE_DO)
  6896. {
  6897. tempIndex = gun_index;
  6898. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6899. {
  6900. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6901. {
  6902. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6903. }
  6904. }
  6905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6906. }
  6907. else
  6908. {
  6909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6910. {
  6911. tempIndex = 2;
  6912. }
  6913. else
  6914. {
  6915. tempIndex = gun_index;
  6916. }
  6917. for (int index = 0; index < AC_QUANTITY; index++)
  6918. {
  6919. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6920. {
  6921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6922. }
  6923. }
  6924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6925. }
  6926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6931. }
  6932. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6933. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6934. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6935. (dataType == ReadingContext_Trigger))
  6936. {
  6937. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6939. {
  6940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6941. {
  6942. tempIndex = ((gun_index==2) ? 1: 0);
  6943. }
  6944. else
  6945. {
  6946. tempIndex = gun_index;
  6947. }
  6948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6949. {
  6950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6951. {
  6952. if(dataType == ReadingContext_Sample_Clock)
  6953. {
  6954. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6955. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6956. }
  6957. else if(dataType == ReadingContext_Sample_Periodic)
  6958. {
  6959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6960. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6961. }
  6962. else
  6963. {
  6964. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6965. }
  6966. }
  6967. } // END OF FOR CHAdeMO_QUANTITY
  6968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6969. }
  6970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6971. {
  6972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6973. {
  6974. tempIndex = ((gun_index==2) ? 1: 0);
  6975. }
  6976. else
  6977. {
  6978. tempIndex = gun_index;
  6979. }
  6980. for (int index = 0; index < CCS_QUANTITY; index++)
  6981. {
  6982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6983. {
  6984. if(dataType == ReadingContext_Sample_Clock)
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6987. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6988. }
  6989. else if(dataType == ReadingContext_Sample_Periodic)
  6990. {
  6991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6992. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6993. }
  6994. else
  6995. {
  6996. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6997. }
  6998. }
  6999. } // END OF CCS_QUANTITY
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7001. }
  7002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7005. {
  7006. tempIndex = ((gun_index==2) ? 1: 0);
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < GB_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7015. {
  7016. if(dataType == ReadingContext_Sample_Clock)
  7017. {
  7018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7019. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7020. }
  7021. else if(dataType == ReadingContext_Sample_Periodic)
  7022. {
  7023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7024. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7025. }
  7026. else
  7027. {
  7028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7029. }
  7030. }
  7031. } // END OF GB_QUANTITY
  7032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7033. }
  7034. else if(gunType[gun_index] == GUN_TYPE_DO)
  7035. {
  7036. tempIndex = gun_index;
  7037. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7038. {
  7039. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7040. {
  7041. if(dataType == ReadingContext_Sample_Clock)
  7042. {
  7043. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7044. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7045. }
  7046. else if(dataType == ReadingContext_Sample_Periodic)
  7047. {
  7048. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7049. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7050. }
  7051. else
  7052. {
  7053. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7054. }
  7055. }
  7056. }
  7057. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7058. }
  7059. else
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7062. {
  7063. tempIndex = 2;
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < AC_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7072. {
  7073. if(dataType == ReadingContext_Sample_Clock)
  7074. {
  7075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7076. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7077. }
  7078. else if(dataType == ReadingContext_Sample_Periodic)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7081. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7082. }
  7083. else
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7086. }
  7087. }
  7088. }
  7089. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7090. }
  7091. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7093. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7095. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7096. }
  7097. //********************************(4)Power.Active.Import************************************************/
  7098. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7099. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7100. (dataType == ReadingContext_Trigger))
  7101. {
  7102. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7103. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7104. {
  7105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7106. {
  7107. tempIndex = ((gun_index==2) ? 1: 0);
  7108. }
  7109. else
  7110. {
  7111. tempIndex = gun_index;
  7112. }
  7113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7114. {
  7115. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7116. {
  7117. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7118. }
  7119. } // END OF FOR
  7120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7121. }
  7122. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7123. {
  7124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7125. {
  7126. tempIndex = ((gun_index==2) ? 1: 0);
  7127. }
  7128. else
  7129. {
  7130. tempIndex = gun_index;
  7131. }
  7132. for (int index = 0; index < CCS_QUANTITY; index++)
  7133. {
  7134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7135. {
  7136. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7137. }
  7138. }
  7139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7140. }
  7141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7142. {
  7143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7144. {
  7145. tempIndex = ((gun_index==2) ? 1: 0);
  7146. }
  7147. else
  7148. {
  7149. tempIndex = gun_index;
  7150. }
  7151. for (int index = 0; index < GB_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].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.GbChargingData[index].PresentChargingPower);
  7157. }
  7158. }
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7160. }
  7161. else if(gunType[gun_index] == GUN_TYPE_DO)
  7162. {
  7163. tempIndex = gun_index;
  7164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7165. {
  7166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7167. {
  7168. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7169. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7170. }
  7171. }
  7172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7173. }
  7174. else
  7175. {
  7176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7177. {
  7178. tempIndex = 2;
  7179. }
  7180. else
  7181. {
  7182. tempIndex = gun_index;
  7183. }
  7184. for (int index = 0; index < AC_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7187. {
  7188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7189. }
  7190. }
  7191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7192. }
  7193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7194. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7195. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7198. }
  7199. //***********************************************(5)VOLTAGE L1******************************************************/
  7200. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7201. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7202. (dataType == ReadingContext_Trigger))
  7203. {
  7204. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7206. {
  7207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7208. {
  7209. tempIndex = ((gun_index==2) ? 1: 0);
  7210. }
  7211. else
  7212. {
  7213. tempIndex = gun_index;
  7214. }
  7215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7216. {
  7217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7218. {
  7219. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7220. }
  7221. }
  7222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7223. }
  7224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7225. {
  7226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7227. {
  7228. tempIndex = ((gun_index==2) ? 1: 0);
  7229. }
  7230. else
  7231. {
  7232. tempIndex = gun_index;
  7233. }
  7234. for (int index = 0; index < CCS_QUANTITY; index++)
  7235. {
  7236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7237. {
  7238. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7239. }
  7240. }
  7241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7242. }
  7243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7244. {
  7245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7246. {
  7247. tempIndex = ((gun_index==2) ? 1: 0);
  7248. }
  7249. else
  7250. {
  7251. tempIndex = gun_index;
  7252. }
  7253. for (int index = 0; index < GB_QUANTITY; index++)
  7254. {
  7255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7256. {
  7257. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7258. }
  7259. }
  7260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7261. }
  7262. else if(gunType[gun_index] == GUN_TYPE_DO)
  7263. {
  7264. tempIndex = gun_index;
  7265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7266. {
  7267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7268. {
  7269. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7270. }
  7271. }
  7272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7273. }
  7274. else
  7275. {
  7276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7277. {
  7278. tempIndex = 2;
  7279. }
  7280. else
  7281. {
  7282. tempIndex = gun_index;
  7283. }
  7284. for (int index = 0; index < AC_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7287. {
  7288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7289. }
  7290. }
  7291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7292. }
  7293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7298. }
  7299. //***********************************************(6)SOC******************************************************/
  7300. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7301. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7302. (dataType == ReadingContext_Trigger))
  7303. {
  7304. 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))
  7305. {
  7306. //idx_sample=5;
  7307. //sampledValue = NULL;
  7308. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7309. {
  7310. tempIndex = ((gun_index==2) ? 1: 0);
  7311. }
  7312. else
  7313. {
  7314. tempIndex = gun_index;
  7315. }
  7316. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7317. {
  7318. //tempIndex = ((gun_index==2) ? 1: 0);
  7319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7320. {
  7321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7322. {
  7323. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7324. }
  7325. }
  7326. }
  7327. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7328. {
  7329. //tempIndex = ((gun_index==2) ? 1: 0);
  7330. for (int index = 0; index < CCS_QUANTITY; index++)
  7331. {
  7332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7333. {
  7334. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7335. }
  7336. }
  7337. }
  7338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7339. {
  7340. //tempIndex = ((gun_index==2) ? 1: 0);
  7341. for (int index = 0; index < GB_QUANTITY; index++)
  7342. {
  7343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7344. {
  7345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7346. }
  7347. }
  7348. }
  7349. else if(gunType[gun_index] == GUN_TYPE_DO)
  7350. {
  7351. //tempIndex = ((gun_index==2) ? 1: 0);
  7352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7353. {
  7354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7355. {
  7356. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7357. }
  7358. }
  7359. }
  7360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7363. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7364. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7366. }
  7367. }
  7368. //********************************(7)Current.Import L2************************************************/
  7369. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7370. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7371. (dataType == ReadingContext_Trigger))
  7372. {
  7373. // Only for AC 3 phase
  7374. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7375. {
  7376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7377. {
  7378. tempIndex = 2;
  7379. }
  7380. else
  7381. {
  7382. tempIndex = gun_index;
  7383. }
  7384. for (int index = 0; index < AC_QUANTITY; index++)
  7385. {
  7386. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7387. {
  7388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7389. }
  7390. }
  7391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7392. }
  7393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7398. }
  7399. //********************************(8)Current.Import L3************************************************/
  7400. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7401. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7402. (dataType == ReadingContext_Trigger))
  7403. {
  7404. // Only for AC 3 phase
  7405. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7406. {
  7407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7408. {
  7409. tempIndex = 2;
  7410. }
  7411. else
  7412. {
  7413. tempIndex = gun_index;
  7414. }
  7415. for (int index = 0; index < AC_QUANTITY; index++)
  7416. {
  7417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7418. {
  7419. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7420. }
  7421. }
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7423. }
  7424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7429. }
  7430. //***********************************************(9)VOLTAGE L2******************************************************/
  7431. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7432. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7433. (dataType == ReadingContext_Trigger))
  7434. {
  7435. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7436. {
  7437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7438. {
  7439. tempIndex = 2;
  7440. }
  7441. else
  7442. {
  7443. tempIndex = gun_index;
  7444. }
  7445. for (int index = 0; index < AC_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7448. {
  7449. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7450. }
  7451. }
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7453. }
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7459. }
  7460. //***********************************************(10)VOLTAGE L3******************************************************/
  7461. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7462. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7463. (dataType == ReadingContext_Trigger))
  7464. {
  7465. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7466. {
  7467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7468. {
  7469. tempIndex = 2;
  7470. }
  7471. else
  7472. {
  7473. tempIndex = gun_index;
  7474. }
  7475. for (int index = 0; index < AC_QUANTITY; index++)
  7476. {
  7477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7478. {
  7479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7480. }
  7481. }
  7482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7483. }
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7489. }
  7490. //***********************************************(11)Current.Offered******************************************************/
  7491. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7492. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7493. (dataType == ReadingContext_Trigger))
  7494. {
  7495. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7497. {
  7498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7499. {
  7500. tempIndex = ((gun_index==2) ? 1: 0);
  7501. }
  7502. else
  7503. {
  7504. tempIndex = gun_index;
  7505. }
  7506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7507. {
  7508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7509. {
  7510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7511. }
  7512. } // END OF FOR CHAdeMO_QUANTITY
  7513. }
  7514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7515. {
  7516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7517. {
  7518. tempIndex = ((gun_index==2) ? 1: 0);
  7519. }
  7520. else
  7521. {
  7522. tempIndex = gun_index;
  7523. }
  7524. for (int index = 0; index < CCS_QUANTITY; index++)
  7525. {
  7526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7527. {
  7528. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7529. }
  7530. } // END OF CCS_QUANTITY
  7531. }
  7532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7533. {
  7534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7535. {
  7536. tempIndex = ((gun_index==2) ? 1: 0);
  7537. }
  7538. else
  7539. {
  7540. tempIndex = gun_index;
  7541. }
  7542. for (int index = 0; index < GB_QUANTITY; index++)
  7543. {
  7544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7545. {
  7546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7547. }
  7548. } // END OF GB_QUANTITY
  7549. }
  7550. else if(gunType[gun_index] == GUN_TYPE_DO)
  7551. {
  7552. tempIndex = gun_index;
  7553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7554. {
  7555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7556. {
  7557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7558. }
  7559. }
  7560. }
  7561. else
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7564. {
  7565. tempIndex = 2;
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < AC_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7574. {
  7575. uint16_t currentOffer;
  7576. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7577. {
  7578. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7579. }
  7580. else
  7581. {
  7582. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7583. }
  7584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7585. }
  7586. }
  7587. }
  7588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7593. }
  7594. //***********************************************(12)Power.Offered******************************************************/
  7595. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7596. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7597. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7598. {
  7599. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7600. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7601. {
  7602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7603. {
  7604. tempIndex = ((gun_index==2) ? 1: 0);
  7605. }
  7606. else
  7607. {
  7608. tempIndex = gun_index;
  7609. }
  7610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7611. {
  7612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7613. {
  7614. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7615. }
  7616. } // END OF FOR CHAdeMO_QUANTITY
  7617. }
  7618. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7619. {
  7620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7621. {
  7622. tempIndex = ((gun_index==2) ? 1: 0);
  7623. }
  7624. else
  7625. {
  7626. tempIndex = gun_index;
  7627. }
  7628. for (int index = 0; index < CCS_QUANTITY; index++)
  7629. {
  7630. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7631. {
  7632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7633. }
  7634. } // END OF CCS_QUANTITY
  7635. }
  7636. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7637. {
  7638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7639. {
  7640. tempIndex = ((gun_index==2) ? 1: 0);
  7641. }
  7642. else
  7643. {
  7644. tempIndex = gun_index;
  7645. }
  7646. for (int index = 0; index < GB_QUANTITY; index++)
  7647. {
  7648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7649. {
  7650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7651. }
  7652. } // END OF GB_QUANTITY
  7653. }
  7654. else if(gunType[gun_index] == GUN_TYPE_DO)
  7655. {
  7656. tempIndex = gun_index;
  7657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7660. {
  7661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7662. }
  7663. }
  7664. }
  7665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7670. }
  7671. // Message create ====================================================================================================
  7672. if(TRUE)
  7673. {
  7674. json_object *MeterValueReq = json_object_new_object();
  7675. json_object *MeterValues = json_object_new_array();
  7676. json_object *sampledValues = json_object_new_array();
  7677. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7678. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7679. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7680. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7681. {
  7682. json_object *MeterValue = json_object_new_object();
  7683. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7684. {
  7685. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7686. {
  7687. json_object *sampledValue = json_object_new_object();
  7688. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7689. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7690. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7691. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7692. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7693. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7694. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7695. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7696. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7697. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7698. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7699. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7700. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7701. json_object_array_add(sampledValues, sampledValue);
  7702. }
  7703. }
  7704. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7705. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7706. json_object_array_add(MeterValues, MeterValue);
  7707. }
  7708. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7709. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7710. ,gun_index + 1
  7711. ,MESSAGE_TYPE_CALL
  7712. ,guid
  7713. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7714. json_object_put(MeterValueReq);
  7715. }
  7716. // Put request guid to hash map
  7717. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7718. 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*/)
  7719. {
  7720. result = PASS;
  7721. //DEBUG_INFO("MeterValues mapitem pass\n");
  7722. }
  7723. if((dataType != ReadingContext_Trigger) &&
  7724. (dataType != ReadingContext_Sample_Clock) &&
  7725. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7726. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7727. else
  7728. {
  7729. if(FirstHeartBeat)
  7730. LWS_Send(queuedata +2);
  7731. }
  7732. return result;
  7733. }
  7734. int sendLogStatusNotificationRequest(char *status)
  7735. {
  7736. mtrace();
  7737. int result = PASS;
  7738. char message[4096]={0};
  7739. char guid[37]={0};
  7740. char tempdata[128]={0};
  7741. json_object *LogStatusNotification = json_object_new_object();
  7742. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7743. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7744. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7745. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7746. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7747. random_uuid(guid);
  7748. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7749. json_object_put(LogStatusNotification);
  7750. LWS_Send(message);
  7751. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7752. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7753. {
  7754. result = PASS;
  7755. }
  7756. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7757. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7758. return result;
  7759. }
  7760. int sendSecurityEventNotificationRequest()
  7761. {
  7762. mtrace();
  7763. int result = PASS;
  7764. char message[4096]={0};
  7765. char guid[37]={0};
  7766. char tempdata[128]={0};
  7767. json_object *SecurityEventNotification = json_object_new_object();
  7768. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7769. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7770. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7771. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7772. random_uuid(guid);
  7773. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7774. json_object_put(SecurityEventNotification);
  7775. LWS_Send(message);
  7776. sprintf(tempdata, "SecurityEventNotification,0");
  7777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7778. {
  7779. result = PASS;
  7780. }
  7781. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7782. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7783. return result;
  7784. }
  7785. int sendSignCertificateRequest()
  7786. {
  7787. mtrace();
  7788. int result = PASS;
  7789. char message[4096]={0};
  7790. char guid[37]={0};
  7791. char tempdata[128]={0};
  7792. json_object *SignCertificate = json_object_new_object();
  7793. DEBUG_INFO("sendSignCertificateRequest...\n");
  7794. // Read csr file content
  7795. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7796. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7797. char *line = NULL;
  7798. size_t len = 0;
  7799. while(getline(&line, &len, fp) != -1)
  7800. {
  7801. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7802. {
  7803. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7804. }
  7805. }
  7806. fclose(fp);
  7807. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7808. random_uuid(guid);
  7809. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7810. json_object_put(SignCertificate);
  7811. LWS_Send(message);
  7812. sprintf(tempdata, "SignCertificate,0");
  7813. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7814. {
  7815. result = PASS;
  7816. }
  7817. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7818. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7819. return result;
  7820. }
  7821. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7822. {
  7823. mtrace();
  7824. int result = PASS;
  7825. char message[110]={0};
  7826. char guid[37]={0};
  7827. char tempdata[65]={0};
  7828. json_object *FirmwareStatusNotification = json_object_new_object();
  7829. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7830. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7831. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7832. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7833. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7834. random_uuid(guid);
  7835. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7836. json_object_put(FirmwareStatusNotification);
  7837. LWS_Send(message);
  7838. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7839. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7840. {
  7841. result = PASS;
  7842. }
  7843. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7844. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7845. return result;
  7846. }
  7847. //==========================================
  7848. // send confirm routine
  7849. //==========================================
  7850. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7851. {
  7852. mtrace();
  7853. int result = FAIL;
  7854. char message[100]={0};
  7855. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7856. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7857. LWS_Send(message);
  7858. result = TRUE;
  7859. return result;
  7860. }
  7861. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7862. {
  7863. mtrace();
  7864. int result = FAIL;
  7865. char message[100]={0};
  7866. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7867. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7868. LWS_Send(message);
  7869. result = TRUE;
  7870. return result;
  7871. }
  7872. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7873. {
  7874. mtrace();
  7875. int result = FAIL;
  7876. char message[100]={0};
  7877. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7879. LWS_Send(message);
  7880. result = TRUE;
  7881. return result;
  7882. }
  7883. int sendClearCacheConfirmation(char *uuid,char *payload)
  7884. {
  7885. mtrace();
  7886. int result = FAIL;
  7887. char message[500]={0};
  7888. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7889. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7890. LWS_Send(message);
  7891. return result;
  7892. }
  7893. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7894. {
  7895. mtrace();
  7896. int result = FAIL;
  7897. char message[500]={0};
  7898. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7899. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7900. LWS_Send(message);
  7901. return result;
  7902. }
  7903. int sendDataTransferConfirmation(char *uuid,char *payload)
  7904. {
  7905. mtrace();
  7906. char statusStr[20]={0};
  7907. char dataStr[10]={0};
  7908. char sstr[20]={0};
  7909. int c = 0;
  7910. char *loc;
  7911. int result = FAIL;
  7912. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7913. /**********************status**************************/
  7914. loc = strstr(payload, "status");
  7915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7916. c = 0;
  7917. while (loc[3+strlen("status")+c] != '\"')
  7918. {
  7919. sstr[c] = loc[3+strlen("status")+c];
  7920. c++;
  7921. }
  7922. sstr[c] = '\0';
  7923. strcpy(statusStr, sstr);
  7924. /**********************data**************************/
  7925. loc = strstr(payload, "data");
  7926. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7927. c = 0;
  7928. while (loc[3+strlen("data")+c] != '\"')
  7929. {
  7930. sstr[c] = loc[3+strlen("data")+c];
  7931. c++;
  7932. }
  7933. sstr[c] = '\0';
  7934. strcpy(dataStr, sstr);
  7935. return result;
  7936. }
  7937. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7938. {
  7939. mtrace();
  7940. int result = FAIL;
  7941. char message[1000]={0};
  7942. int CompositeScheduleIndex = 0;
  7943. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7944. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7945. if(nPeriod == 0)
  7946. {
  7947. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7948. {
  7949. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7950. ,MESSAGE_TYPE_CALLRESULT
  7951. ,uuid
  7952. ,payload
  7953. ,connectorIdInt);
  7954. }
  7955. else
  7956. {
  7957. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7958. ,MESSAGE_TYPE_CALLRESULT
  7959. ,uuid
  7960. ,payload
  7961. ,connectorIdInt
  7962. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7965. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7966. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7967. }
  7968. }
  7969. else
  7970. {
  7971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7972. ,MESSAGE_TYPE_CALLRESULT
  7973. ,uuid
  7974. ,payload
  7975. ,connectorIdInt
  7976. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7977. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7978. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7979. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7980. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7981. {
  7982. if (idx_sample == 0)
  7983. {
  7984. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7985. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7986. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7987. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7988. }
  7989. else
  7990. {
  7991. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7992. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7993. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7995. }
  7996. }
  7997. sprintf(message + strlen(message), "]}}]");
  7998. }
  7999. LWS_Send(message);
  8000. result = TRUE;
  8001. return result;
  8002. }
  8003. int sendGetConfigurationConfirmation(char *uuid)
  8004. {
  8005. mtrace();
  8006. int result = FAIL;
  8007. int MaxKeySupported = 0;
  8008. int sentConfigurationNumber= 0;
  8009. int sentunConfigurationNumber= 0;
  8010. char message[1024*10]={0};
  8011. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8012. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8013. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8014. ,MESSAGE_TYPE_CALLRESULT
  8015. ,uuid );
  8016. //configuration key
  8017. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8018. {
  8019. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8020. {
  8021. if (sentConfigurationNumber == 0)
  8022. {
  8023. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8024. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8025. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8026. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8027. }
  8028. else
  8029. {
  8030. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8031. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8032. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8033. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8034. }
  8035. sentConfigurationNumber = sentConfigurationNumber + 1;
  8036. }
  8037. }
  8038. sprintf(message + strlen(message), "]");
  8039. if(UnknownKeynum != 0)
  8040. {
  8041. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8042. //unkown key
  8043. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8044. {
  8045. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8046. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8047. if(sentunConfigurationNumber == 0)
  8048. {
  8049. sprintf(message + strlen(message), "\"%s\""
  8050. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8051. }
  8052. else
  8053. {
  8054. sprintf(message + strlen(message), ",\"%s\""
  8055. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8056. }
  8057. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8058. }
  8059. sprintf(message + strlen(message), "]");
  8060. }
  8061. sprintf(message + strlen(message), "}]");
  8062. LWS_Send(message);
  8063. return result;
  8064. }
  8065. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8066. {
  8067. mtrace();
  8068. int result = FAIL;
  8069. char message[400]={0};
  8070. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8071. if(strcmp(payload,"")==0)
  8072. {
  8073. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8074. }
  8075. else
  8076. {
  8077. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8078. }
  8079. LWS_Send(message);
  8080. result = TRUE;
  8081. return result;
  8082. }
  8083. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8084. {
  8085. mtrace();
  8086. int result = FAIL;
  8087. char message[80]={0};
  8088. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8089. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8090. LWS_Send(message);
  8091. result = TRUE;
  8092. return result;
  8093. }
  8094. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8095. {
  8096. mtrace();
  8097. int result = FAIL;
  8098. char message[80]={0};
  8099. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8100. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8101. LWS_Send(message);
  8102. result = TRUE;
  8103. return result;
  8104. }
  8105. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8106. {
  8107. mtrace();
  8108. int result = FAIL;
  8109. char message[80]={0};
  8110. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8112. LWS_Send(message);
  8113. result = TRUE;
  8114. return result;
  8115. }
  8116. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8117. {
  8118. mtrace();
  8119. int result = FAIL;
  8120. char message[80]={0};
  8121. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8122. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8123. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8124. LWS_Send(message);
  8125. result = TRUE;
  8126. return result;
  8127. }
  8128. int sendResetConfirmation(char *uuid,char *payload)
  8129. {
  8130. mtrace();
  8131. int result = FAIL;
  8132. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8133. char message[80]={0};
  8134. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8135. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8136. LWS_Send(message);
  8137. result = TRUE;
  8138. return result;
  8139. }
  8140. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8141. {
  8142. mtrace();
  8143. int result = FAIL;
  8144. char message[500]={0};
  8145. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8146. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8147. LWS_Send(message);
  8148. result = TRUE;
  8149. return result;
  8150. }
  8151. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8152. {
  8153. mtrace();
  8154. int result = FAIL;
  8155. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8156. char message[80]={0};
  8157. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8158. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8159. LWS_Send(message);
  8160. result = TRUE;
  8161. return result;
  8162. }
  8163. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8164. {
  8165. mtrace();
  8166. int result = FAIL;
  8167. char message[80]={0};
  8168. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8169. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8170. LWS_Send(message);
  8171. result = TRUE;
  8172. return result;
  8173. }
  8174. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8175. {
  8176. mtrace();
  8177. int result = FAIL;
  8178. char message[80]={0};
  8179. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8180. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8182. LWS_Send(message);
  8183. result = TRUE;
  8184. return result;
  8185. }
  8186. int sendUpdateFirmwareConfirmation(char *uuid)
  8187. {
  8188. mtrace();
  8189. int result = FAIL;
  8190. char message[60]={0};
  8191. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8192. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8194. LWS_Send(message);
  8195. result = TRUE;
  8196. return result;
  8197. }
  8198. int sendCertificateSignedConfirmation(char *uuid)
  8199. {
  8200. mtrace();
  8201. int result = PASS;
  8202. char message[4096]={0};
  8203. json_object *CertificateSigned = json_object_new_object();
  8204. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8205. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8206. sprintf(message,"[%d,\"%s\",%s]"
  8207. ,MESSAGE_TYPE_CALLRESULT
  8208. ,uuid
  8209. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8210. json_object_put(CertificateSigned);
  8211. LWS_Send(message);
  8212. return result;
  8213. }
  8214. int sendDeleteCertificateConfirmation(char *uuid)
  8215. {
  8216. mtrace();
  8217. int result = PASS;
  8218. char message[4096]={0};
  8219. json_object *DeleteCertificate = json_object_new_object();
  8220. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8221. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8222. sprintf(message,"[%d,\"%s\",%s]"
  8223. ,MESSAGE_TYPE_CALLRESULT
  8224. ,uuid
  8225. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8226. json_object_put(DeleteCertificate);
  8227. LWS_Send(message);
  8228. return result;
  8229. }
  8230. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8231. {
  8232. mtrace();
  8233. int result = PASS;
  8234. char message[4096]={0};
  8235. json_object *ExtendedTriggerMessage = json_object_new_object();
  8236. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8237. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8238. sprintf(message,"[%d,\"%s\",%s]"
  8239. ,MESSAGE_TYPE_CALLRESULT
  8240. ,uuid
  8241. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8242. json_object_put(ExtendedTriggerMessage);
  8243. LWS_Send(message);
  8244. return result;
  8245. }
  8246. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8247. {
  8248. mtrace();
  8249. int result = PASS;
  8250. char message[4096]={0};
  8251. json_object *GetInstalledCertificateIds = json_object_new_object();
  8252. json_object *certificateHashDataDatas = json_object_new_array();
  8253. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8254. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8255. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8256. {
  8257. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8258. {
  8259. json_object *certificateHashData = json_object_new_object();
  8260. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8261. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8262. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8263. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8264. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8265. }
  8266. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8267. }
  8268. else
  8269. {
  8270. json_object_put(certificateHashDataDatas);
  8271. }
  8272. sprintf(message,"[%d,\"%s\",%s]"
  8273. ,MESSAGE_TYPE_CALLRESULT
  8274. ,uuid
  8275. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8276. json_object_put(GetInstalledCertificateIds);
  8277. LWS_Send(message);
  8278. return result;
  8279. }
  8280. int sendGetLogConfirmation(char *uuid)
  8281. {
  8282. mtrace();
  8283. int result = PASS;
  8284. char message[4096]={0};
  8285. json_object *GetLog = json_object_new_object();
  8286. DEBUG_INFO("sendGetLogConfirmation...\n");
  8287. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8288. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8289. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8290. sprintf(message,"[%d,\"%s\",%s]"
  8291. ,MESSAGE_TYPE_CALLRESULT
  8292. ,uuid
  8293. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8294. json_object_put(GetLog);
  8295. LWS_Send(message);
  8296. return result;
  8297. }
  8298. int sendInstallCertificateConfirmation(char *uuid)
  8299. {
  8300. mtrace();
  8301. int result = PASS;
  8302. char message[4096]={0};
  8303. json_object *InstallCertificate = json_object_new_object();
  8304. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8305. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8306. sprintf(message,"[%d,\"%s\",%s]"
  8307. ,MESSAGE_TYPE_CALLRESULT
  8308. ,uuid
  8309. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8310. json_object_put(InstallCertificate);
  8311. LWS_Send(message);
  8312. return result;
  8313. }
  8314. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8315. {
  8316. mtrace();
  8317. int result = PASS;
  8318. char message[4096]={0};
  8319. json_object *SignedUpdateFirmware = json_object_new_object();
  8320. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8321. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8322. sprintf(message,"[%d,\"%s\",%s]"
  8323. ,MESSAGE_TYPE_CALLRESULT
  8324. ,uuid
  8325. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8326. json_object_put(SignedUpdateFirmware);
  8327. LWS_Send(message);
  8328. return result;
  8329. }
  8330. int sendUnknownConfirmation(char *uuid)
  8331. {
  8332. mtrace();
  8333. int result = PASS;
  8334. char message[256]={0};
  8335. DEBUG_INFO("sendUnknownConfirmation...\n");
  8336. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8337. LWS_Send(message);
  8338. return result;
  8339. }
  8340. //==========================================
  8341. // Handle server request routine Start
  8342. //==========================================
  8343. int handleCancelReservationRequest(char *uuid, char *payload)
  8344. {
  8345. mtrace();
  8346. int result = FAIL;
  8347. int gunNO = 0;
  8348. int reservationIdInt = -1;
  8349. char comfirmstr[20];
  8350. DEBUG_INFO("handleCancelReservationRequest...\n");
  8351. json_object *CancelReservation;
  8352. CancelReservation = json_tokener_parse(payload);
  8353. if(!is_error(CancelReservation))
  8354. {
  8355. // Required data
  8356. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8357. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8358. }
  8359. json_object_put(CancelReservation);
  8360. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8361. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8362. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8363. if(reservationIdInt != -1)
  8364. {
  8365. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8366. //check Transaction active
  8367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8369. {
  8370. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8371. {
  8372. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8373. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8374. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8375. {
  8376. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8377. }
  8378. else
  8379. {
  8380. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8381. }
  8382. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8383. goto end;
  8384. }
  8385. }
  8386. for (int index = 0; index < CCS_QUANTITY; index++)
  8387. {
  8388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8389. {
  8390. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8391. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8392. if(gunType[2] == GUN_TYPE_CCS)
  8393. {
  8394. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8395. }
  8396. else
  8397. {
  8398. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8399. }
  8400. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8401. goto end;
  8402. }
  8403. }
  8404. for (int index = 0; index < GB_QUANTITY; index++)
  8405. {
  8406. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8407. {
  8408. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8409. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8410. if(gunType[2] == GUN_TYPE_GBT)
  8411. {
  8412. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8413. }
  8414. else
  8415. {
  8416. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8417. }
  8418. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8419. goto end;
  8420. }
  8421. }
  8422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8423. {
  8424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8425. {
  8426. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8427. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8428. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8429. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8430. goto end;
  8431. }
  8432. }
  8433. for (int index = 0; index < AC_QUANTITY; index++)
  8434. {
  8435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8436. {
  8437. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8438. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8440. {
  8441. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8442. }
  8443. else
  8444. {
  8445. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8446. }
  8447. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8448. goto end;
  8449. }
  8450. }
  8451. }
  8452. //The reservationId does NOT match the reservationId
  8453. sendCancelReservationConfirmation(uuid, comfirmstr);
  8454. end:
  8455. // Fill in ocpp packet uuid
  8456. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8457. return result;
  8458. }
  8459. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8460. {
  8461. mtrace();
  8462. int result = FAIL;
  8463. int gunIndex = -1;
  8464. char typeStr[16]={0};
  8465. char comfirmstr[20];
  8466. int specificId = FALSE;
  8467. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8468. json_object *ChangeAvailability;
  8469. ChangeAvailability = json_tokener_parse(payload);
  8470. if(!is_error(ChangeAvailability))
  8471. {
  8472. // Required data
  8473. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8474. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8475. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8476. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8477. }
  8478. json_object_put(ChangeAvailability);
  8479. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8480. {
  8481. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8482. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8483. }
  8484. else if(gunIndex == 0)
  8485. {
  8486. for(int i=0; i < gunTotalNumber; i++)
  8487. {
  8488. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8489. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8490. }
  8491. }
  8492. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8494. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8495. {
  8496. specificId = TRUE;
  8497. }
  8498. if(specificId == FALSE)
  8499. goto end;
  8500. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8501. {
  8502. //----------------------gunIndex is 0 ------------------------------------------------//
  8503. if(gunIndex == 0)
  8504. {
  8505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8506. {
  8507. for(int i=0; i < gunTotalNumber; i++)
  8508. {
  8509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8510. {
  8511. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8512. {
  8513. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8514. {
  8515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8516. goto end;
  8517. }
  8518. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8523. {
  8524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8525. goto end;
  8526. }
  8527. }
  8528. }//END FOR CHAdeMO_QUANTITY
  8529. for (int index = 0; index < CCS_QUANTITY; index++)
  8530. {
  8531. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8532. {
  8533. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8534. {
  8535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8536. goto end;
  8537. }
  8538. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8539. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8540. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8541. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8543. {
  8544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8545. goto end;
  8546. }
  8547. }
  8548. }//END FOR CCS_QUANTITY
  8549. for (int index = 0; index < GB_QUANTITY; index++)
  8550. {
  8551. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8552. {
  8553. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8554. {
  8555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8556. goto end;
  8557. }
  8558. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8559. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8560. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8561. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8563. {
  8564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8565. goto end;
  8566. }
  8567. }
  8568. }// END FOR GB_QUANTITY
  8569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8570. {
  8571. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8572. {
  8573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8574. {
  8575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8576. goto end;
  8577. }
  8578. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8579. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8583. {
  8584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8585. goto end;
  8586. }
  8587. }
  8588. }// END FOR GENERAL_GUN_QUANTITY
  8589. for (int index = 0; index < AC_QUANTITY; index++)
  8590. {
  8591. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8592. {
  8593. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8594. {
  8595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8596. goto end;
  8597. }
  8598. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8599. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8600. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8601. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8602. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8603. {
  8604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8605. goto end;
  8606. }
  8607. }
  8608. }//END FOR AC_QUANTITY
  8609. }// END FOR gunTotalNumber
  8610. }
  8611. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8612. {
  8613. for(int i=0; i < gunTotalNumber; i++)
  8614. {
  8615. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8616. {
  8617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8618. goto end;
  8619. }
  8620. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8623. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8625. {
  8626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8627. goto end;
  8628. }
  8629. }
  8630. }
  8631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8632. goto end;
  8633. }
  8634. //----------------------gunIndex is not 0 ------------------------------------------------//
  8635. //check Transaction active
  8636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8637. {
  8638. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8639. {
  8640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8641. {
  8642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8643. goto end;
  8644. }
  8645. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8647. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8648. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8649. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8650. {
  8651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8652. goto end;
  8653. }
  8654. else
  8655. {
  8656. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8658. goto end;
  8659. }
  8660. }
  8661. }//END FOR CHAdeMO_QUANTITY
  8662. for (int index = 0; index < CCS_QUANTITY; index++)
  8663. {
  8664. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8665. {
  8666. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8667. {
  8668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8669. goto end;
  8670. }
  8671. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8672. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8673. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8674. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8675. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8676. {
  8677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8678. goto end;
  8679. }
  8680. else
  8681. {
  8682. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8684. goto end;
  8685. }
  8686. }
  8687. }//END FOR CCS_QUANTITY
  8688. for (int index = 0; index < GB_QUANTITY; index++)
  8689. {
  8690. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8691. {
  8692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8693. {
  8694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8695. goto end;
  8696. }
  8697. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8698. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8702. {
  8703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8704. goto end;
  8705. }
  8706. else
  8707. {
  8708. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8710. goto end;
  8711. }
  8712. }
  8713. }// END FOR GB_QUANTITY
  8714. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8715. {
  8716. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8717. {
  8718. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8719. {
  8720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8721. goto end;
  8722. }
  8723. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8724. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8725. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8726. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8728. {
  8729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8730. goto end;
  8731. }
  8732. else
  8733. {
  8734. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8736. goto end;
  8737. }
  8738. }
  8739. }// END FOR GENERAL_GUN_QUANTITY
  8740. for (int index = 0; index < AC_QUANTITY; index++)
  8741. {
  8742. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8743. {
  8744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8745. {
  8746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8747. goto end;
  8748. }
  8749. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8750. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8751. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8752. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8754. {
  8755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8756. goto end;
  8757. }
  8758. else
  8759. {
  8760. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8762. goto end;
  8763. }
  8764. }
  8765. }//END FOR AC_QUANTITY
  8766. }//END FOR AvailabilityTypeStr[Inoperative]
  8767. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8768. {
  8769. //----------------------gunIndex is 0 ------------------------------------------------//
  8770. if(gunIndex == 0)
  8771. {
  8772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8773. {
  8774. for(int i=0; i < gunTotalNumber; i++)
  8775. {
  8776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8777. {
  8778. 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
  8779. {
  8780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8781. goto end;
  8782. }
  8783. }//END FOR CHAdeMO_QUANTITY
  8784. for (int index = 0; index < CCS_QUANTITY; index++)
  8785. {
  8786. 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
  8787. {
  8788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8789. goto end;
  8790. }
  8791. }//END FOR CCS_QUANTITY
  8792. for (int index = 0; index < GB_QUANTITY; index++)
  8793. {
  8794. 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
  8795. {
  8796. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8798. goto end;
  8799. }
  8800. }// END FOR GB_QUANTITY
  8801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8802. {
  8803. 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
  8804. {
  8805. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8807. goto end;
  8808. }
  8809. }// END FOR GENERAL_GUN_QUANTITY
  8810. for (int index = 0; index < AC_QUANTITY; index++)
  8811. {
  8812. 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
  8813. {
  8814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8815. goto end;
  8816. }
  8817. }//END FOR CHAdeMO_QUANTITY
  8818. }// END FOR gunTotalNumber
  8819. }
  8820. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8821. {
  8822. for(int i=0; i < gunTotalNumber; i++)
  8823. {
  8824. for (int index = 0; index < AC_QUANTITY; index++)
  8825. {
  8826. 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
  8827. {
  8828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8829. goto end;
  8830. }
  8831. }//END FOR CHAdeMO_QUANTITY
  8832. } // END FOR gunTotalNumber
  8833. }
  8834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8835. goto end;
  8836. }
  8837. //----------------------gunIndex is not 0 ------------------------------------------------//
  8838. //check Transaction active
  8839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8840. {
  8841. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8842. {
  8843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8844. goto end;
  8845. }
  8846. }//END FOR CHAdeMO_QUANTITY
  8847. for (int index = 0; index < CCS_QUANTITY; index++)
  8848. {
  8849. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8850. {
  8851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8852. goto end;
  8853. }
  8854. }//END FOR CCS_QUANTITY
  8855. for (int index = 0; index < GB_QUANTITY; index++)
  8856. {
  8857. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8858. {
  8859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8860. goto end;
  8861. }
  8862. }// END FOR GB_QUANTITY
  8863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8864. {
  8865. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8866. {
  8867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8868. goto end;
  8869. }
  8870. }// END FOR GENERAL_GUN_QUANTITY
  8871. for (int index = 0; index < AC_QUANTITY; index++)
  8872. {
  8873. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8874. {
  8875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8876. goto end;
  8877. }
  8878. }//END FOR AC_QUANTITY
  8879. }//END FOR AvailabilityTypeStr[Operative]
  8880. end:
  8881. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8882. {
  8883. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8884. }
  8885. else
  8886. {
  8887. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8888. }
  8889. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8890. {
  8891. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8892. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8893. }
  8894. else if(gunIndex == 0)
  8895. {
  8896. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8897. {
  8898. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8899. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8900. }
  8901. }
  8902. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8903. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8904. return result;
  8905. }
  8906. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8907. {
  8908. mtrace();
  8909. int valueInvalid = NO;
  8910. int result = FAIL;
  8911. char keystr[40]={0};
  8912. char valuestr[501]={0}; //value should be limited in 500 bytes
  8913. char comfirmstr[20]={0};
  8914. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8915. json_object *ChangeConfiguration;
  8916. ChangeConfiguration = json_tokener_parse(payload);
  8917. if(!is_error(ChangeConfiguration))
  8918. {
  8919. // Required data
  8920. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8921. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8922. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8923. {
  8924. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8925. }
  8926. else
  8927. {
  8928. valueInvalid = YES;
  8929. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8930. }
  8931. }
  8932. json_object_put(ChangeConfiguration);
  8933. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8934. {
  8935. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8936. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8937. }
  8938. else
  8939. {
  8940. int status = setKeyValue(keystr, valuestr);
  8941. switch(status)
  8942. {
  8943. case ConfigurationStatus_Accepted:
  8944. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8945. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8946. StoreConfigurationTable();
  8947. break;
  8948. case RebootRequired:
  8949. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8950. StoreConfigurationTable();
  8951. break;
  8952. case NotSupported:
  8953. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8954. break;
  8955. case ConfigurationStatus_Rejected:
  8956. default:
  8957. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8958. break;
  8959. }
  8960. }
  8961. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8962. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8963. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8964. {
  8965. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8966. SetOcppConnStatus(FALSE);
  8967. }
  8968. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8969. {
  8970. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8971. }
  8972. return result;
  8973. }
  8974. int handleClearCacheRequest(char *uuid, char *payload)
  8975. {
  8976. mtrace();
  8977. int result = FAIL;
  8978. char comfirmstr[20];
  8979. char rmFileCmd[100]={0};
  8980. struct stat stats;
  8981. DEBUG_INFO("handleClearCacheRequest...\n");
  8982. stat("/Storage/OCPP", &stats);
  8983. // Check for directory existence
  8984. if (S_ISDIR(stats.st_mode) == 1)
  8985. {}
  8986. else
  8987. {
  8988. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8989. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8990. system(rmFileCmd);
  8991. }
  8992. if(OCPP_cleanLocalCache())
  8993. {
  8994. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8995. }
  8996. else
  8997. {
  8998. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8999. }
  9000. sendClearCacheConfirmation(uuid, comfirmstr);
  9001. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9002. return result;
  9003. }
  9004. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9005. {
  9006. mtrace();
  9007. int result = FAIL;
  9008. int resultRename;
  9009. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9010. char chargingProfilePurposeStr[26]={0};
  9011. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9012. char tempchargingProfilePurposeStr[26]={0};
  9013. char str[100]={0};
  9014. char fname[200]={0};
  9015. char comfirmstr[20]={0};
  9016. char word[1600]={0};
  9017. int clearflag = FALSE;
  9018. int chargingProfileIdIsNULL = FALSE;
  9019. int connectorIsNULL = FALSE;
  9020. int chargingProfilePurposeIsNULL = FALSE;
  9021. int stackLevelIsNULL = FALSE;
  9022. //int GotoEnd = FALSE;
  9023. FILE *fptr1, *fptr2;
  9024. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9025. int n_chargingProfile=0;
  9026. int isEmptyFile = FALSE;
  9027. char sLineWord[1600]={0};
  9028. char chargingProfiles[10][100]={0};
  9029. int ChargeProfileCount = 0;
  9030. int ch;
  9031. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9032. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9033. json_object *ClearChargingProfile;
  9034. ClearChargingProfile = json_tokener_parse(payload);
  9035. if(!is_error(ClearChargingProfile))
  9036. {
  9037. // Optional data
  9038. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9039. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9040. else
  9041. chargingProfileIdIsNULL = TRUE;
  9042. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9043. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9044. else
  9045. connectorIsNULL = TRUE;
  9046. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9047. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9048. else
  9049. chargingProfilePurposeIsNULL = TRUE;
  9050. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9051. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9052. else
  9053. stackLevelIsNULL = TRUE;
  9054. }
  9055. json_object_put(ClearChargingProfile);
  9056. if(connectorIsNULL == FALSE)
  9057. {
  9058. switch(connectorIdInt)
  9059. {
  9060. case 0:
  9061. if(chargingProfilePurposeIsNULL == TRUE)
  9062. {
  9063. int l = 0;
  9064. strcpy(fname, ChargePointMaxProfile_JSON);
  9065. if((access(fname,F_OK))!=-1)
  9066. {
  9067. strcpy(chargingProfiles[l], fname);
  9068. l = l + 1;
  9069. }
  9070. strcpy(fname, TxDefaultProfile_0_JSON);
  9071. if((access(fname,F_OK))!=-1)
  9072. {
  9073. strcpy(chargingProfiles[l], fname);
  9074. l = l + 1;
  9075. }
  9076. ChargeProfileCount = l;
  9077. }
  9078. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9079. {
  9080. strcpy(fname, ChargePointMaxProfile_JSON);
  9081. if((access(fname,F_OK))!=-1)
  9082. {
  9083. strcpy(chargingProfiles[0], fname);
  9084. ChargeProfileCount = 1;
  9085. }
  9086. }
  9087. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9088. {
  9089. strcpy(fname, TxDefaultProfile_0_JSON);
  9090. if((access(fname,F_OK))!=-1)
  9091. {
  9092. strcpy(chargingProfiles[0], fname);
  9093. ChargeProfileCount = 1;
  9094. }
  9095. }
  9096. break;
  9097. default:
  9098. if(chargingProfilePurposeIsNULL == TRUE)
  9099. {
  9100. int m = 0;
  9101. memset(fname, 0, ARRAY_SIZE(fname));
  9102. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9103. if((access(fname,F_OK))!=-1)
  9104. {
  9105. strcpy(chargingProfiles[m], fname);
  9106. m = m + 1;
  9107. }
  9108. memset(fname, 0, ARRAY_SIZE(fname));
  9109. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9110. if((access(fname,F_OK))!=-1)
  9111. {
  9112. strcpy(chargingProfiles[m], fname);
  9113. m = m + 1;
  9114. }
  9115. ChargeProfileCount = m;
  9116. }
  9117. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9118. {
  9119. //strcpy(fname, TxDefaultProfile_1_JSON);
  9120. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9121. if((access(fname,F_OK))!=-1)
  9122. {
  9123. strcpy(chargingProfiles[0], fname);
  9124. ChargeProfileCount = 1;
  9125. }
  9126. }
  9127. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9128. {
  9129. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9130. if((access(fname,F_OK))!=-1)
  9131. {
  9132. strcpy(chargingProfiles[0], fname);
  9133. ChargeProfileCount = 1;
  9134. }
  9135. //strcpy(fname, TxProfile_1_JSON);
  9136. }
  9137. //strcpy(fname, ChargePointMaxProfile_JSON );
  9138. break;
  9139. }
  9140. }
  9141. else // Check all Charging Profiles
  9142. {
  9143. int i = 0;
  9144. char fnametemp[200]={0};
  9145. ChargeProfileCount = 0;
  9146. //Check ChargePointMaxProfile.json exit
  9147. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9148. {
  9149. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9150. i = i + 1;
  9151. }
  9152. //Check TxDefaultProfile_0.json exit
  9153. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9154. {
  9155. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9156. i = i + 1;
  9157. }
  9158. //Check TxDefaultProfile_%d.json
  9159. for(int j=1; j <= gunTotalNumber; j++)
  9160. {
  9161. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9162. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9163. if((access(fnametemp,F_OK))!=-1)
  9164. {
  9165. strcpy(chargingProfiles[i], fnametemp);
  9166. i = i + 1;
  9167. }
  9168. }
  9169. //Check TxProfile_%d.json
  9170. for(int j=1; j <= gunTotalNumber; j++)
  9171. {
  9172. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9173. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9174. if((access(fnametemp,F_OK))!=-1)
  9175. {
  9176. strcpy(chargingProfiles[i], fnametemp);
  9177. i = i + 1;
  9178. }
  9179. }
  9180. ChargeProfileCount = i;
  9181. }// End connectorIsNULL is TRUE
  9182. if(ChargeProfileCount == 0)
  9183. {
  9184. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9185. goto end;
  9186. }
  9187. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9188. {
  9189. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9190. goto end;
  9191. }
  9192. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9193. {
  9194. memset(str, 0, ARRAY_SIZE(str));
  9195. // clear temp file
  9196. sprintf(str,"rm -f %s",temp);
  9197. system(str);
  9198. for(int k=0; k < ChargeProfileCount; k++)
  9199. {
  9200. memset(str, 0, ARRAY_SIZE(str));
  9201. //clear file in C
  9202. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9203. system(str);
  9204. }
  9205. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9206. goto end;
  9207. }
  9208. else if(connectorIsNULL == TRUE)
  9209. {
  9210. for(int k=0; k < ChargeProfileCount; k++)
  9211. {
  9212. fptr1 = fopen(chargingProfiles[k], "r");
  9213. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9214. //Check Charging Profile Count
  9215. while(fscanf(fptr1, "%s", word) != EOF)
  9216. {
  9217. //DEBUG_INFO("word=%s\n",word);
  9218. if(strstr(word, "chargingProfileId")!= NULL)
  9219. {
  9220. //DEBUG_INFO("test chargingProfileId \n");
  9221. n_chargingProfile = n_chargingProfile + 1;
  9222. //DEBUG_INFO("chargingProfileId Found\n");
  9223. }
  9224. }
  9225. rewind(fptr1);
  9226. //search Charging Profile Element
  9227. //int i= 0;
  9228. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9229. {
  9230. json_object *tmpProfilee;
  9231. tmpProfilee = json_tokener_parse(sLineWord);
  9232. if(!is_error(tmpProfilee))
  9233. {
  9234. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9235. {
  9236. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9237. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9238. }
  9239. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9240. {
  9241. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9242. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9243. }
  9244. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9245. {
  9246. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9247. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9248. }
  9249. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9250. {
  9251. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9252. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9253. }
  9254. }
  9255. json_object_put(tmpProfilee);
  9256. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9257. {
  9258. //------- not write to fptr2-------//
  9259. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9260. //clearflag = TRUE;
  9261. }
  9262. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9263. {
  9264. //------- not write to fptr2-------//
  9265. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9266. }
  9267. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9268. {
  9269. //------- not write to fptr2-------//
  9270. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9271. }
  9272. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9273. {
  9274. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9275. }
  9276. else
  9277. {
  9278. fprintf(fptr2, sLineWord);//writing data into file
  9279. }
  9280. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9281. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9282. if(clearflag == TRUE)
  9283. {
  9284. fclose(fptr1);
  9285. fclose(fptr2);
  9286. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9287. system(str);
  9288. // clear temp file
  9289. sprintf(str,"rm -f %s",temp);
  9290. system(str);
  9291. }
  9292. else
  9293. {
  9294. fclose(fptr1);
  9295. fclose(fptr2);
  9296. memset(str, 0, ARRAY_SIZE(str));
  9297. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9298. system(str);
  9299. resultRename = rename(temp, chargingProfiles[k]);
  9300. if(resultRename == 0)
  9301. {
  9302. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9303. }
  9304. else
  9305. {
  9306. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9307. }
  9308. if(comfirmstr[0]== 0)
  9309. {
  9310. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9311. }
  9312. //Check chargingProfile is empty file
  9313. /*------ Read the file ----------------*/
  9314. fptr1=fopen(chargingProfiles[k],"r");
  9315. ch=fgetc(fptr1);
  9316. rewind(fptr1);
  9317. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9318. if(ch!=EOF)
  9319. {
  9320. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9321. {
  9322. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9323. if(sLineWord[0]=='\0')
  9324. {
  9325. isEmptyFile = TRUE;
  9326. break;
  9327. }
  9328. else
  9329. {
  9330. isEmptyFile = FALSE;
  9331. break;
  9332. }
  9333. }
  9334. }
  9335. else
  9336. isEmptyFile = TRUE;
  9337. fclose(fptr1);
  9338. if(isEmptyFile == TRUE)
  9339. {
  9340. memset(str, 0, ARRAY_SIZE(str));
  9341. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9342. system(str);
  9343. }
  9344. }
  9345. }// End of while(int k=0; k < ChargePointCount; k++)
  9346. }
  9347. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9348. {
  9349. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9350. for(int k=0; k < ChargeProfileCount; k++)
  9351. {
  9352. fptr1 = fopen(chargingProfiles[k], "r");
  9353. fptr2 = fopen(temp, "w+");
  9354. //Check Charging Profile Count
  9355. while(fscanf(fptr1, "%s", word) != EOF)
  9356. {
  9357. //DEBUG_INFO("word=%s\n",word);
  9358. if(strstr(word, "chargingProfileId")!= NULL)
  9359. {
  9360. n_chargingProfile = n_chargingProfile + 1;
  9361. }
  9362. }
  9363. rewind(fptr1);
  9364. //search Charging Profile Element
  9365. //int i= 0;
  9366. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9367. {
  9368. json_object *tmpProfilee;
  9369. tmpProfilee = json_tokener_parse(sLineWord);
  9370. if(!is_error(tmpProfilee))
  9371. {
  9372. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9373. {
  9374. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9375. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9376. }
  9377. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9378. {
  9379. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9380. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9381. }
  9382. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9383. {
  9384. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9385. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9386. }
  9387. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9388. {
  9389. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9390. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9391. }
  9392. }
  9393. json_object_put(tmpProfilee);
  9394. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9395. {
  9396. //------- not write to fptr2-------//
  9397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9398. //clearflag = TRUE;
  9399. }
  9400. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9401. {
  9402. //------- not write to fptr2-------//
  9403. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9404. }
  9405. else if(stackLevelIsNULL == TRUE)
  9406. {
  9407. //Clear Whole File
  9408. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9409. clearflag = TRUE;
  9410. break;
  9411. }
  9412. else
  9413. {
  9414. fprintf(fptr2, sLineWord);//writing data into file
  9415. }
  9416. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9417. }
  9418. if(clearflag == TRUE)
  9419. {
  9420. fclose(fptr1);
  9421. fclose(fptr2);
  9422. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9423. system(str);
  9424. // clear temp file
  9425. sprintf(str,"rm -f %s",temp);
  9426. system(str);
  9427. }
  9428. else
  9429. {
  9430. fclose(fptr1);
  9431. fclose(fptr2);
  9432. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9433. system(str);
  9434. resultRename = rename(temp, chargingProfiles[k]);
  9435. if(resultRename == 0)
  9436. {
  9437. DEBUG_INFO("File ChargingProfile renamed successfully");
  9438. }
  9439. else
  9440. {
  9441. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9442. }
  9443. if(comfirmstr[0]== 0)
  9444. {
  9445. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9446. }
  9447. //Check chargingProfile is empty file
  9448. /*------ Read the file ----------------*/
  9449. fptr1=fopen(chargingProfiles[k],"r");
  9450. ch=fgetc(fptr1);
  9451. rewind(fptr1);
  9452. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9453. if(ch!=EOF)
  9454. {
  9455. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9456. {
  9457. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9458. if(sLineWord[0]=='\0')
  9459. {
  9460. isEmptyFile = TRUE;
  9461. break;
  9462. }
  9463. else
  9464. {
  9465. isEmptyFile = FALSE;
  9466. break;
  9467. }
  9468. }
  9469. }
  9470. else
  9471. isEmptyFile = TRUE;
  9472. fclose(fptr1);
  9473. if(isEmptyFile == TRUE)
  9474. {
  9475. memset(str, 0, ARRAY_SIZE(str));
  9476. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9477. system(str);
  9478. }
  9479. /*------- End of reading ---------------*/
  9480. }
  9481. } // while(int k=0; k < ChargeProfileCount; k++)
  9482. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9483. end:
  9484. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9485. {
  9486. if(connectorIdInt == 0)
  9487. {
  9488. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9489. {
  9490. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9491. }
  9492. }
  9493. else
  9494. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9495. }
  9496. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9497. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9498. return result;
  9499. }
  9500. void createFirmwareVersionByDataTransfer(void)
  9501. {
  9502. json_object *FirmwareDataTransfer = json_object_new_object();
  9503. // AC & DC model
  9504. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9505. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9506. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9507. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9508. // DC model
  9509. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9510. {
  9511. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9512. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9513. (gunType[3] != GUN_TYPE_UNKNOWN))
  9514. {
  9515. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9516. }
  9517. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9518. {
  9519. // DS DM DW
  9520. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9521. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9522. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9523. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9524. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9525. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9526. }
  9527. else
  9528. {
  9529. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9530. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9531. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9532. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9533. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9534. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9535. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9536. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9537. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9538. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9539. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9540. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9541. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9542. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9543. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9544. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9545. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9546. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9547. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9548. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9549. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9550. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9551. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9552. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9553. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9554. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9555. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9556. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9557. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9558. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9559. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9560. }
  9561. }
  9562. // 4G model
  9563. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9564. {
  9565. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9566. }
  9567. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9568. json_object_put(FirmwareDataTransfer);
  9569. }
  9570. int handleDataTransferRequest(char *uuid, char *payload)
  9571. {
  9572. mtrace();
  9573. json_object *response = json_object_new_object();
  9574. int result = FAIL;
  9575. char tempvendorId[255]={0};
  9576. char tempmessageId[50]={0};
  9577. char tempdata[1024]={0};
  9578. char message[2048]={0};
  9579. DEBUG_INFO("handleDataTransferRequest...\n");
  9580. if((uuid != NULL) && (payload != NULL))
  9581. {
  9582. json_object *DataTransfer;
  9583. DataTransfer = json_tokener_parse(payload);
  9584. if(!is_error(DataTransfer))
  9585. {
  9586. // Required data
  9587. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9588. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9589. // Optional data
  9590. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9591. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9592. if(json_object_object_get(DataTransfer, "data") != NULL)
  9593. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9594. result = PASS;
  9595. }
  9596. json_object_put(DataTransfer);
  9597. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9598. {
  9599. // Send all moudle firmware version on EVSE
  9600. createFirmwareVersionByDataTransfer();
  9601. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9602. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9603. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9604. json_object_put(response);
  9605. }
  9606. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9607. {
  9608. system("/usr/bin/run_tmate_restart.sh &");
  9609. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9610. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9611. json_object_put(response);
  9612. }
  9613. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9614. {
  9615. json_object *data;
  9616. data = json_tokener_parse(tempdata);
  9617. if(!is_error(data))
  9618. {
  9619. 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))
  9620. {
  9621. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9622. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9623. if(json_object_object_get(data, "SOC") != NULL)
  9624. {
  9625. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9626. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9627. }
  9628. if(json_object_object_get(data, "Energy") != NULL)
  9629. {
  9630. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9631. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9632. }
  9633. if(json_object_object_get(data, "Duration") != NULL)
  9634. {
  9635. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9636. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9637. }
  9638. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9639. }
  9640. else
  9641. {
  9642. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9643. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9644. }
  9645. }
  9646. else
  9647. {
  9648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9649. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9650. }
  9651. json_object_put(data);
  9652. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9653. json_object_put(response);
  9654. }
  9655. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9656. {
  9657. json_object *data;
  9658. data = json_tokener_parse(tempdata);
  9659. if(!is_error(data))
  9660. {
  9661. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9662. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9663. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9664. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9665. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9666. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9667. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9668. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9669. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9670. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9671. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9672. }
  9673. else
  9674. {
  9675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9677. }
  9678. json_object_put(data);
  9679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9680. json_object_put(response);
  9681. }
  9682. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9683. {
  9684. json_object *data;
  9685. data = json_tokener_parse(tempdata);
  9686. if(!is_error(data))
  9687. {
  9688. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9689. if(json_object_object_get(data, "idToken") != NULL)
  9690. {
  9691. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9692. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9693. }
  9694. if(json_object_object_get(data, "price") != NULL)
  9695. {
  9696. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9697. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9698. }
  9699. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9700. }
  9701. else
  9702. {
  9703. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9704. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9705. }
  9706. json_object_put(data);
  9707. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9708. json_object_put(response);
  9709. }
  9710. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9711. {
  9712. json_object *data;
  9713. data = json_tokener_parse(tempdata);
  9714. if(!is_error(data))
  9715. {
  9716. if(json_object_object_get(data, "txId") != NULL)
  9717. {
  9718. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9719. for(int idx = 0;idx<gunTotalNumber;idx++)
  9720. {
  9721. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9722. {
  9723. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9724. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9725. if(json_object_object_get(data, "description") != NULL)
  9726. {
  9727. // California pricing V1.0
  9728. DEBUG_INFO("California pricing V1.0\n");
  9729. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9730. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9731. }
  9732. else
  9733. {
  9734. // California pricing V1.1
  9735. DEBUG_INFO("California pricing V1.1\n");
  9736. if(json_object_object_get(data, "timestamp") != NULL)
  9737. {
  9738. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9739. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9740. }
  9741. if(json_object_object_get(data, "meterValue") != NULL)
  9742. {
  9743. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9744. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9745. }
  9746. if(json_object_object_get(data, "cost") != NULL)
  9747. {
  9748. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9749. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9750. }
  9751. if(json_object_object_get(data, "state") != NULL)
  9752. {
  9753. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9754. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9755. }
  9756. if(json_object_object_get(data, "chargingPrice") != NULL)
  9757. {
  9758. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9759. {
  9760. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9761. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9762. }
  9763. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9764. {
  9765. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9766. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9767. }
  9768. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9769. {
  9770. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9771. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9772. }
  9773. }
  9774. if(json_object_object_get(data, "idlePrice") != NULL)
  9775. {
  9776. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9777. {
  9778. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9779. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9780. }
  9781. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9782. {
  9783. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9784. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9785. }
  9786. }
  9787. if(json_object_object_get(data, "nextPeriod") != NULL)
  9788. {
  9789. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9790. {
  9791. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9792. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9793. }
  9794. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9795. {
  9796. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9797. {
  9798. 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")));
  9799. 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"));
  9800. }
  9801. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9802. {
  9803. 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")));
  9804. 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"));
  9805. }
  9806. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9807. {
  9808. 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")));
  9809. 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"));
  9810. }
  9811. }
  9812. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9813. {
  9814. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9815. {
  9816. 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")));
  9817. 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"));
  9818. }
  9819. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9820. {
  9821. 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")));
  9822. 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"));
  9823. }
  9824. }
  9825. }
  9826. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9827. {
  9828. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9829. {
  9830. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9831. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9832. }
  9833. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9834. {
  9835. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9836. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9837. }
  9838. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9839. {
  9840. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9841. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9842. }
  9843. }
  9844. }
  9845. }
  9846. }
  9847. }
  9848. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9849. }
  9850. else
  9851. {
  9852. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9853. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9854. }
  9855. json_object_put(data);
  9856. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9857. json_object_put(response);
  9858. }
  9859. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9860. {
  9861. json_object *data;
  9862. data = json_tokener_parse(tempdata);
  9863. if(!is_error(data))
  9864. {
  9865. if(json_object_object_get(data, "txId") != NULL)
  9866. {
  9867. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9868. for(int idx = 0;idx<gunTotalNumber;idx++)
  9869. {
  9870. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9871. {
  9872. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9873. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9874. if(json_object_object_get(data, "description") != NULL)
  9875. {
  9876. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9877. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9878. }
  9879. }
  9880. }
  9881. }
  9882. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9883. }
  9884. else
  9885. {
  9886. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9887. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9888. }
  9889. json_object_put(data);
  9890. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9891. json_object_put(response);
  9892. }
  9893. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9894. {
  9895. json_object *data;
  9896. data = json_tokener_parse(tempdata);
  9897. if(!is_error(data))
  9898. {
  9899. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9900. if(json_object_object_get(data, "Content_Type") != NULL)
  9901. {
  9902. 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))
  9903. {
  9904. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9905. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9906. {
  9907. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9908. }
  9909. }
  9910. else
  9911. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9912. }
  9913. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9914. }
  9915. else
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9918. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9919. }
  9920. json_object_put(data);
  9921. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9922. json_object_put(response);
  9923. }
  9924. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9925. {
  9926. json_object *data;
  9927. data = json_tokener_parse(tempdata);
  9928. if(!is_error(data))
  9929. {
  9930. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9931. if(json_object_object_get(data, "ConnectorId") != NULL)
  9932. {
  9933. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9934. }
  9935. if(json_object_object_get(data, "SerialNo") != NULL)
  9936. {
  9937. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9938. }
  9939. if(json_object_object_get(data, "Page_Index") != NULL)
  9940. {
  9941. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9942. }
  9943. if(json_object_object_get(data, "Duration") != NULL)
  9944. {
  9945. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9946. }
  9947. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9948. }
  9949. else
  9950. {
  9951. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9952. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9953. }
  9954. json_object_put(data);
  9955. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9956. json_object_put(response);
  9957. }
  9958. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9959. {
  9960. json_object *data;
  9961. data = json_tokener_parse(tempdata);
  9962. if(!is_error(data))
  9963. {
  9964. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9965. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9966. {
  9967. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9968. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9969. else
  9970. {
  9971. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9972. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9973. }
  9974. }
  9975. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9976. {
  9977. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9978. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9979. else
  9980. {
  9981. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9982. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9983. }
  9984. }
  9985. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9986. {
  9987. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9988. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9989. else
  9990. {
  9991. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9992. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9993. }
  9994. }
  9995. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9996. {
  9997. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9998. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9999. else
  10000. {
  10001. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10002. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10003. }
  10004. }
  10005. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10006. {
  10007. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10008. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10009. else
  10010. {
  10011. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10012. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10013. }
  10014. }
  10015. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10016. {
  10017. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10018. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10019. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10020. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10021. else
  10022. {
  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. }
  10026. }
  10027. if(json_object_object_get(data, "isAuthentication") != NULL)
  10028. {
  10029. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10030. {
  10031. case 0:
  10032. case 1:
  10033. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10034. break;
  10035. default:
  10036. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10037. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10038. break;
  10039. }
  10040. }
  10041. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10042. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10043. }
  10044. else
  10045. {
  10046. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10047. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10048. }
  10049. json_object_put(data);
  10050. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10051. json_object_put(response);
  10052. }
  10053. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10054. {
  10055. json_object *data;
  10056. data = json_tokener_parse(tempdata);
  10057. if(!is_error(data))
  10058. {
  10059. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10060. {
  10061. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10062. {
  10063. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10064. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10065. }
  10066. else
  10067. {
  10068. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10069. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10070. }
  10071. }
  10072. else
  10073. {
  10074. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10075. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10076. }
  10077. }
  10078. else
  10079. {
  10080. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10081. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10082. }
  10083. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10084. json_object_put(response);
  10085. }
  10086. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10087. {
  10088. json_object *data;
  10089. data = json_tokener_parse(tempdata);
  10090. if(!is_error(data))
  10091. {
  10092. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10093. if(json_object_object_get(data, "stationName") != NULL)
  10094. {
  10095. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10096. }
  10097. else
  10098. {
  10099. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10100. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10101. }
  10102. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10103. {
  10104. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10105. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10106. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10107. }
  10108. }
  10109. else
  10110. {
  10111. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10112. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10113. }
  10114. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10115. json_object_put(response);
  10116. }
  10117. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10118. {
  10119. json_object *data;
  10120. data = json_tokener_parse(tempdata);
  10121. if(!is_error(data))
  10122. {
  10123. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10124. if(json_object_object_get(data, "weatherId") != NULL)
  10125. {
  10126. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10127. }
  10128. else
  10129. {
  10130. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10131. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10132. }
  10133. if(json_object_object_get(data, "Temperature") != NULL)
  10134. {
  10135. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10136. }
  10137. else
  10138. {
  10139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10140. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10141. }
  10142. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10143. {
  10144. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10145. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10146. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10147. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10148. );
  10149. }
  10150. }
  10151. else
  10152. {
  10153. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10154. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10155. }
  10156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10157. json_object_put(response);
  10158. }
  10159. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10160. {
  10161. json_object *data;
  10162. data = json_tokener_parse(tempdata);
  10163. if(!is_error(data))
  10164. {
  10165. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10166. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10167. {
  10168. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10169. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10170. }
  10171. else
  10172. {
  10173. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10174. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10175. }
  10176. }
  10177. else
  10178. {
  10179. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10180. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10181. }
  10182. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10183. json_object_put(response);
  10184. }
  10185. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10186. {
  10187. json_object *data;
  10188. data = json_tokener_parse(tempdata);
  10189. if(!is_error(data))
  10190. {
  10191. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10192. {
  10193. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10194. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10195. if(gun_index < gunTotalNumber)
  10196. {
  10197. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10198. {
  10199. json_object *responsedata = json_object_new_object();
  10200. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10201. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10202. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10203. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10204. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10205. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10206. }
  10207. else
  10208. {
  10209. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10210. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10211. }
  10212. }
  10213. else
  10214. {
  10215. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10216. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10217. }
  10218. }
  10219. else
  10220. {
  10221. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10222. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10223. }
  10224. }
  10225. else
  10226. {
  10227. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10228. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10229. }
  10230. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10231. json_object_put(response);
  10232. }
  10233. else
  10234. {
  10235. // Can not find valid message id
  10236. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10237. }
  10238. }
  10239. else
  10240. {
  10241. // Payload is null
  10242. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10243. }
  10244. LWS_Send(message);
  10245. return result;
  10246. }
  10247. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10248. {
  10249. mtrace();
  10250. int result = FAIL;
  10251. int connectorIdInt, durationInt;
  10252. char chargingRateUnitStr[4]={0};
  10253. char comfirmstr[20];
  10254. int confirmPeriods = 0;
  10255. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10256. json_object *GetCompositeSchedule;
  10257. GetCompositeSchedule = json_tokener_parse(payload);
  10258. if(!is_error(GetCompositeSchedule))
  10259. {
  10260. // Required data
  10261. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10262. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10263. else
  10264. connectorIdInt = -1;
  10265. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10266. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10267. else
  10268. durationInt = 86400;
  10269. // Optional data
  10270. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10271. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10272. }
  10273. json_object_put(GetCompositeSchedule);
  10274. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10275. if((connectorIdInt == 0) ||
  10276. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10277. {
  10278. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10279. struct StructChargingProfile tmpProfile[1];
  10280. if(strstr(chargingRateUnitStr, "W") != NULL)
  10281. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10282. else
  10283. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10284. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10285. {
  10286. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10287. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10288. }
  10289. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10290. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10291. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10292. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10293. {
  10294. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10295. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10296. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10297. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10298. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10299. {
  10300. confirmPeriods = idx;
  10301. break;
  10302. }
  10303. }
  10304. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10305. {
  10306. confirmPeriods += 1;
  10307. }
  10308. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10309. }
  10310. else
  10311. {
  10312. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10313. }
  10314. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10315. return result;
  10316. }
  10317. int handleGetConfigurationRequest(char *uuid, char *payload)
  10318. {
  10319. mtrace();
  10320. int result = FAIL;
  10321. int MaxKeySupported = 0;
  10322. int n_keys = 0;
  10323. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10324. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10325. json_object *GetConfiguration;
  10326. GetConfiguration = json_tokener_parse(payload);
  10327. if(!is_error(GetConfiguration))
  10328. {
  10329. // Optional data
  10330. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10331. {
  10332. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10333. {
  10334. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10335. n_keys = idx + 1;
  10336. }
  10337. }
  10338. }
  10339. json_object_put(GetConfiguration);
  10340. UnknownKeynum = 0;
  10341. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10342. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10343. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10344. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10345. if(n_keys != 0)
  10346. {
  10347. for(int i=0;i<n_keys;i++)
  10348. {
  10349. getKeyValue(requestKey[i]);
  10350. }
  10351. }
  10352. else
  10353. {
  10354. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10355. getKeyValue("");
  10356. }
  10357. processUnkownKey();
  10358. sendGetConfigurationConfirmation(uuid);
  10359. return result;
  10360. }
  10361. static char fnamePlusPath[100]={0};
  10362. static char fnamePWithNoPath[60]={0};
  10363. void checkUploadLog(void)
  10364. {
  10365. FILE *fp;
  10366. /* Open the command for reading. */
  10367. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10368. if (fp == NULL) {
  10369. DEBUG_WARN("Failed to run command\n" );
  10370. exit(1);
  10371. }
  10372. int ftppathlen = 0;
  10373. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10374. int i = 0;
  10375. /* Read the output a line at a time - output it. */
  10376. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10377. if(i==0)
  10378. {
  10379. ftppathlen = strlen(fnamePlusPath);
  10380. DEBUG_INFO("%s\n", fnamePlusPath);
  10381. fnamePlusPath[ftppathlen]='\0';
  10382. break;
  10383. }
  10384. i= i+1;
  10385. }
  10386. /* close */
  10387. pclose(fp);
  10388. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10389. {
  10390. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10391. {
  10392. fnamePlusPath[k]='\0';
  10393. }
  10394. }
  10395. i=1;
  10396. //char fname[60]={0};
  10397. while(i < ftppathlen)
  10398. {
  10399. int len=ftppathlen-i;
  10400. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10401. {
  10402. DEBUG_INFO("compare '/' all right\n");
  10403. break;
  10404. }
  10405. i=i+1;
  10406. }
  10407. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10408. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10409. fnamePWithNoPath[i+1] = '\0';
  10410. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10411. {
  10412. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10413. {
  10414. fnamePWithNoPath[j]='\0';
  10415. }
  10416. }
  10417. FILE* fp1 = fopen(fnamePlusPath, "r");
  10418. if (fp1)
  10419. {
  10420. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10421. // file exists
  10422. fclose(fp1);
  10423. }
  10424. else
  10425. {
  10426. // file doesn't exist
  10427. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10428. }
  10429. }
  10430. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10431. {
  10432. mtrace();
  10433. int result = FAIL;
  10434. time_t CurrentTime;
  10435. struct tm *tm;
  10436. pthread_t th_Status;
  10437. CurrentTime = time(NULL);
  10438. tm = localtime(&CurrentTime);
  10439. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10440. 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);
  10441. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10442. if(!interLock.isGetDiagnosticGoing)
  10443. {
  10444. interLock.isGetDiagnosticGoing = 1;
  10445. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10446. sleep(1);
  10447. }
  10448. else
  10449. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10450. return result;
  10451. }
  10452. void* GetDiagnosticsProcess(void* data)
  10453. {
  10454. pthread_detach(pthread_self());
  10455. mtrace();
  10456. int retriesInt=0, retryIntervalInt=0;
  10457. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10458. 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};
  10459. int port=0;
  10460. int isSuccess = FALSE;
  10461. char cmdBuf[2048];
  10462. struct tm *tmNow;
  10463. time_t CurrentTime;
  10464. struct tm tmStart;
  10465. struct tm tmStop;
  10466. CurrentTime = time(NULL);
  10467. tmNow=localtime(&CurrentTime);
  10468. uint16_t targetYear, targetMonth;
  10469. json_object *GetDiagnostics;
  10470. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10471. GetDiagnostics = json_tokener_parse(data);
  10472. if(!is_error(GetDiagnostics))
  10473. {
  10474. // Required data
  10475. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10476. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10477. // Optional data
  10478. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10479. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10480. else
  10481. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10482. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10483. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10484. else
  10485. retryIntervalInt = 30;
  10486. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10487. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10488. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10489. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10490. }
  10491. json_object_put(GetDiagnostics);
  10492. // Pack log to compress file
  10493. 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) &&
  10494. (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))
  10495. {
  10496. // Pack system log
  10497. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10498. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10499. targetYear = tmStart.tm_year;
  10500. targetMonth = tmStart.tm_mon;
  10501. do
  10502. {
  10503. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10504. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10505. if(targetMonth+1>=13)
  10506. {
  10507. targetYear += 1;
  10508. targetMonth = 1;
  10509. }
  10510. else
  10511. {
  10512. targetMonth += 1;
  10513. }
  10514. }while((targetYear < (tmNow->tm_year+1900)) ||
  10515. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10516. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10517. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10518. system(cmdBuf);
  10519. // Pack charging & event log
  10520. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10521. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10522. targetYear = tmStart.tm_year;
  10523. targetMonth = tmStart.tm_mon;
  10524. do
  10525. {
  10526. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10527. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10528. if(targetMonth+1>=13)
  10529. {
  10530. targetYear += 1;
  10531. targetMonth = 1;
  10532. }
  10533. else
  10534. {
  10535. targetMonth += 1;
  10536. }
  10537. }while((targetYear < (tmNow->tm_year+1900)) ||
  10538. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10539. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10540. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10541. system(cmdBuf);
  10542. // Combine log file
  10543. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10544. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10545. }
  10546. else
  10547. {
  10548. system("exec /root/logPackTools 'log' 6");
  10549. }
  10550. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10551. system(cmdBuf);
  10552. checkUploadLog();
  10553. //****************location*******************/
  10554. if(strcmp(locationstr,"")==0)
  10555. {
  10556. DEBUG_INFO("location is <Empty>!\n");
  10557. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10558. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10559. goto end;
  10560. }
  10561. memset(protocol, 0, ARRAY_SIZE(protocol));
  10562. memset(user, 0, ARRAY_SIZE(user) );
  10563. memset(password, 0, ARRAY_SIZE(password));
  10564. memset(host, 0, ARRAY_SIZE(host));
  10565. memset(path, 0, ARRAY_SIZE(path));
  10566. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10567. memset(host1, 0, ARRAY_SIZE(host1));
  10568. memset(path1, 0, ARRAY_SIZE(path1));
  10569. /*location: ftp://user:password@host:port/path*/
  10570. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10571. if((access(fnamePlusPath,F_OK))!=-1)
  10572. {
  10573. DEBUG_INFO("fnamePlusPath exist.\n");
  10574. }
  10575. else
  10576. {
  10577. DEBUG_INFO("fnamePlusPath not exist!\n");
  10578. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10579. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10580. goto end;
  10581. }
  10582. if(strchr(locationstr,'@')==NULL)
  10583. {
  10584. sscanf(locationstr,
  10585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10586. protocol, host, &port, path);
  10587. strcpy(user,"anonymous");
  10588. strcpy(password,"");
  10589. }
  10590. else
  10591. {
  10592. //DEBUG_INFO("pch=%s\n", pch);
  10593. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10594. protocol, user, password, host, &port, path);
  10595. }
  10596. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10597. {
  10598. DEBUG_INFO("protocol is not ftp/http ! \n");
  10599. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10600. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10601. goto end;
  10602. }
  10603. if(strncmp(locationstr,"http", 4) == 0)
  10604. {
  10605. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10606. sprintf(ftppath,"/%s", path);
  10607. do
  10608. {
  10609. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10610. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10611. sleep(3);
  10612. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10613. if(!isSuccess)
  10614. {
  10615. DEBUG_INFO("Diagnostics fail.\n");
  10616. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10617. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10618. sleep(retryIntervalInt);
  10619. }
  10620. else
  10621. {
  10622. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10623. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10624. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10625. }
  10626. retriesInt--;
  10627. }while((isSuccess == 0)&&(retriesInt >= 0));
  10628. }
  10629. else
  10630. {
  10631. sscanf(host,"%[^/]%s",host1, path1);
  10632. if(strlen(path) > 0)
  10633. sprintf(ftppath,"/%s", path);
  10634. else
  10635. sprintf(ftppath,"/%s", path1);
  10636. int ftppathlen=strlen(ftppath);
  10637. int i=1;
  10638. char filenametemp[50];
  10639. while(i < ftppathlen)
  10640. {
  10641. int len=ftppathlen-i;
  10642. if(ftppath[len]== 47) // '/' ascll code: 47
  10643. {
  10644. DEBUG_INFO("find '/' all right\n");
  10645. break;
  10646. }
  10647. i=i+1;
  10648. }
  10649. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10650. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10651. filenametemp[i+1] = 0;
  10652. if(port == 0)
  10653. port = 21;
  10654. do
  10655. {
  10656. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10657. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10658. sleep(3);
  10659. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10660. if(!isSuccess)
  10661. {
  10662. DEBUG_INFO("Diagnostics fail.\n");
  10663. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10664. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10665. sleep(retryIntervalInt);
  10666. }
  10667. else
  10668. {
  10669. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10670. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10671. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10672. }
  10673. retriesInt--;
  10674. }while((!isSuccess)&&(retriesInt >= 0));
  10675. }
  10676. end:
  10677. system("rm -f /mnt/*");
  10678. sleep(5);
  10679. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10680. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10681. interLock.isGetDiagnosticGoing = 0;
  10682. pthread_exit(NULL);
  10683. }
  10684. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10685. {
  10686. mtrace();
  10687. int result = FAIL;
  10688. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10689. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10690. {
  10691. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10692. locallistVersion = -1;
  10693. }
  10694. else
  10695. {
  10696. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10697. locallistVersion = 0;
  10698. OCPP_getListVerion();
  10699. }
  10700. //from db.OCPP_getListVerion
  10701. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10702. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10703. sendGetLocalListVersionConfirmation(uuid,"");
  10704. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10705. return result;
  10706. }
  10707. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10708. {
  10709. mtrace();
  10710. int result = FAIL;
  10711. int connectorIdInt=-1;
  10712. int tempIndex = 0;
  10713. int connectorIdIsNULL, chargingProfileIsNULL;
  10714. char comfirmstr[20]={0};
  10715. char cmdBuf[512];
  10716. json_object *RemoteStartTransaction;
  10717. FILE *fp;
  10718. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10719. if(server_pending == TRUE)
  10720. {
  10721. return 0;
  10722. }
  10723. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10724. RemoteStartTransaction = json_tokener_parse(payload);
  10725. if(!is_error(RemoteStartTransaction))
  10726. {
  10727. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10728. {
  10729. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10730. }
  10731. else
  10732. {
  10733. connectorIdIsNULL = TRUE;
  10734. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10735. {
  10736. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10737. {
  10738. connectorIdIsNULL = FALSE;
  10739. connectorIdInt = (gun_index+1);
  10740. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10741. break;
  10742. }
  10743. }
  10744. }
  10745. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10746. {
  10747. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10748. // Required data
  10749. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10750. // Optional data
  10751. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10752. {
  10753. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10754. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10755. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10756. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10757. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10758. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10759. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10760. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10761. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10762. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10763. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10764. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10765. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10766. {
  10767. 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")));
  10768. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10769. 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"));
  10770. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10771. 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"));
  10772. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10773. 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")));
  10774. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10775. {
  10776. 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++)
  10777. {
  10778. 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"));
  10779. 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"));
  10780. 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)
  10781. 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"));
  10782. }
  10783. }
  10784. }
  10785. }
  10786. else
  10787. {
  10788. chargingProfileIsNULL = TRUE;
  10789. }
  10790. }
  10791. }
  10792. else
  10793. {
  10794. connectorIdIsNULL = TRUE;
  10795. }
  10796. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10797. {
  10798. DEBUG_WARN("Connector id is NULL\n.");
  10799. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10800. goto end;
  10801. }
  10802. /*
  10803. enum _SYSTEM_STATUS
  10804. {
  10805. S_BOOTING = 0,
  10806. S_IDLE, = 1
  10807. S_AUTHORIZING, = 2
  10808. S_REASSIGN_CHECK, = 3
  10809. S_REASSIGN, = 4
  10810. S_PRECHARGE, = 5
  10811. S_PREPARING_FOR_EV, = 6
  10812. S_PREPARING_FOR_EVSE, = 7
  10813. S_CHARGING, = 8
  10814. S_TERMINATING, = 9
  10815. S_COMPLETE, = 10
  10816. S_ALARM, = 11
  10817. S_FAULT = 12
  10818. }
  10819. */
  10820. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10821. {
  10822. //check Transaction active
  10823. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10824. {
  10825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10826. {
  10827. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10828. }
  10829. else
  10830. {
  10831. tempIndex = connectorIdInt -1;
  10832. }
  10833. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10834. {
  10835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10836. {
  10837. 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))
  10838. {
  10839. //Reserved
  10840. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10841. }
  10842. 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))
  10843. {
  10844. //Reserved
  10845. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10847. goto end;
  10848. }
  10849. else
  10850. {
  10851. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10852. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10853. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10854. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10855. {
  10856. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10857. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10858. goto end;
  10859. }
  10860. }//END FOR ELSE
  10861. }
  10862. }// END FOR CHAdeMO_QUANTITY
  10863. }
  10864. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10865. {
  10866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10867. {
  10868. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10869. }
  10870. else
  10871. {
  10872. tempIndex = connectorIdInt -1;
  10873. }
  10874. for (int index = 0; index < CCS_QUANTITY; index++)
  10875. {
  10876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10877. {
  10878. 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))
  10879. {
  10880. //Reserved
  10881. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10882. }
  10883. 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))
  10884. {
  10885. //Reserved
  10886. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10887. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10888. goto end;
  10889. }
  10890. else
  10891. {
  10892. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10893. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10894. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10895. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10896. {
  10897. DEBUG_WARN("CCS connector not allow start\n.");
  10898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10899. goto end;
  10900. }
  10901. }// END FOR ELSE
  10902. }
  10903. }// END FOR CCS_QUANTITY
  10904. }
  10905. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10906. {
  10907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10908. {
  10909. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10910. }
  10911. else
  10912. {
  10913. tempIndex = connectorIdInt -1;
  10914. }
  10915. for (int index = 0; index < GB_QUANTITY; index++)
  10916. {
  10917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10918. {
  10919. 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))
  10920. {
  10921. //Reserved
  10922. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10923. }
  10924. 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))
  10925. {
  10926. //Reserved
  10927. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10928. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10929. goto end;
  10930. }
  10931. else
  10932. {
  10933. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10934. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10935. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10936. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10937. {
  10938. DEBUG_WARN("GB connector not allow start\n.");
  10939. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10940. goto end;
  10941. }
  10942. }// END FOR ELSE
  10943. }
  10944. } // END FOR GB_QUANTITY
  10945. }
  10946. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10947. {
  10948. tempIndex = connectorIdInt -1;
  10949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10950. {
  10951. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10952. {
  10953. 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))
  10954. {
  10955. //Reserved
  10956. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10957. }
  10958. 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))
  10959. {
  10960. //Reserved
  10961. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10963. goto end;
  10964. }
  10965. else
  10966. {
  10967. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10968. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10969. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10970. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10971. {
  10972. DEBUG_WARN("GB connector not allow start\n.");
  10973. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10974. goto end;
  10975. }
  10976. }// END FOR ELSE
  10977. }
  10978. } // END FOR GB_QUANTITY
  10979. }
  10980. else
  10981. {
  10982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10983. {
  10984. tempIndex = 2;
  10985. }
  10986. else
  10987. {
  10988. tempIndex = connectorIdInt -1;
  10989. }
  10990. for (int index = 0; index < AC_QUANTITY; index++)
  10991. {
  10992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10993. {
  10994. 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))
  10995. {
  10996. //Reserved
  10997. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10998. }
  10999. 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))
  11000. {
  11001. //Reserved
  11002. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11003. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11004. goto end;
  11005. }
  11006. else
  11007. {
  11008. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11009. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11010. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11011. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11012. {
  11013. DEBUG_WARN("AC connector not allow start\n.");
  11014. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11015. goto end;
  11016. }
  11017. }//END FOR ELSE
  11018. }
  11019. }// END FOR AC_QUANTITY
  11020. }
  11021. if(chargingProfileIsNULL == FALSE)
  11022. {
  11023. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11024. {
  11025. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11026. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11027. //memset idTag
  11028. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11029. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11030. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11031. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11032. // Save profile to file
  11033. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11034. system(cmdBuf);
  11035. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11036. fp = fopen(cmdBuf, "w");
  11037. 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));
  11038. fclose(fp);
  11039. }
  11040. else
  11041. {
  11042. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11043. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11044. }
  11045. }
  11046. else
  11047. {
  11048. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11050. //memset idTag
  11051. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11052. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11053. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11054. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11055. }
  11056. }
  11057. else
  11058. {
  11059. DEBUG_WARN("Connector id over\n.");
  11060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11061. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11062. }
  11063. end:
  11064. json_object_put(RemoteStartTransaction);
  11065. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11066. {
  11067. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11068. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11069. }
  11070. //OCPP send RemoteStartConfirmation by first.
  11071. sendRemoteStartConfirmation(uuid, comfirmstr);
  11072. return result;
  11073. }
  11074. int handleRemoteStartRequest(char *uuid, char *payload)
  11075. {
  11076. mtrace();
  11077. int result = PASS;
  11078. int connectorIdInt=-1;
  11079. int tempIndex = 0;
  11080. char comfirmstr[20]={0};
  11081. char cmdBuf[512];
  11082. json_object *RemoteStartTransaction;
  11083. FILE *fp;
  11084. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11085. if(server_pending == TRUE)
  11086. {
  11087. result = FAIL;
  11088. }
  11089. RemoteStartTransaction = json_tokener_parse(payload);
  11090. if(!is_error(RemoteStartTransaction))
  11091. {
  11092. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11093. {
  11094. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11095. }
  11096. else
  11097. {
  11098. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11099. {
  11100. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11101. {
  11102. connectorIdInt = (gun_index+1);
  11103. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11104. break;
  11105. }
  11106. }
  11107. }
  11108. if(connectorIdInt == 0)
  11109. {
  11110. DEBUG_WARN("Connector id shall not equal 0.\n");
  11111. result = FAIL;
  11112. }
  11113. else if(connectorIdInt == -1)
  11114. {
  11115. DEBUG_INFO("Connector id does not specific.\n");
  11116. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11117. {
  11118. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11119. // Required data
  11120. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11121. // Optional data
  11122. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11123. {
  11124. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11125. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11126. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11127. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11128. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11129. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11130. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11131. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11132. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11133. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11134. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11135. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11136. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11137. {
  11138. 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")));
  11139. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11140. 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"));
  11141. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11142. 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"));
  11143. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11144. 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")));
  11145. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11146. {
  11147. 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++)
  11148. {
  11149. 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"));
  11150. 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"));
  11151. 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)
  11152. 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"));
  11153. }
  11154. }
  11155. }
  11156. }
  11157. else
  11158. {
  11159. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11160. }
  11161. }
  11162. }
  11163. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11164. {
  11165. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11166. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11167. // Required data
  11168. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11169. // Optional data
  11170. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11171. {
  11172. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11174. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11175. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11176. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11177. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11178. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11179. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11180. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11181. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11182. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11183. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11184. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11185. {
  11186. 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")));
  11187. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11188. 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"));
  11189. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11190. 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"));
  11191. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11192. 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")));
  11193. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11194. {
  11195. 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++)
  11196. {
  11197. 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"));
  11198. 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"));
  11199. 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)
  11200. 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"));
  11201. }
  11202. }
  11203. }
  11204. }
  11205. else
  11206. {
  11207. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11208. }
  11209. }
  11210. else
  11211. {
  11212. DEBUG_WARN("Connector id is over maximun value.\n");
  11213. result = FAIL;
  11214. }
  11215. }
  11216. if(result == PASS)
  11217. {
  11218. if(connectorIdInt > 0)
  11219. {
  11220. //check Transaction active
  11221. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11222. {
  11223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11224. {
  11225. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11226. }
  11227. else
  11228. {
  11229. tempIndex = connectorIdInt -1;
  11230. }
  11231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11232. {
  11233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11234. {
  11235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11236. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11237. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11238. {
  11239. //Reserved
  11240. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11241. }
  11242. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11243. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11244. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11245. {
  11246. //Reserved
  11247. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11248. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11249. goto end;
  11250. }
  11251. else
  11252. {
  11253. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11254. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11255. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11256. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11257. {
  11258. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11259. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11260. goto end;
  11261. }
  11262. }//END FOR ELSE
  11263. }
  11264. }// END FOR CHAdeMO_QUANTITY
  11265. }
  11266. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11267. {
  11268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11269. {
  11270. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11271. }
  11272. else
  11273. {
  11274. tempIndex = connectorIdInt -1;
  11275. }
  11276. for (int index = 0; index < CCS_QUANTITY; index++)
  11277. {
  11278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11279. {
  11280. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11281. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11282. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11283. {
  11284. //Reserved
  11285. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11286. }
  11287. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11289. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11290. {
  11291. //Reserved
  11292. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11294. goto end;
  11295. }
  11296. else
  11297. {
  11298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11299. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11300. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11301. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11302. {
  11303. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11305. goto end;
  11306. }
  11307. }// END FOR ELSE
  11308. }
  11309. }// END FOR CCS_QUANTITY
  11310. }
  11311. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11312. {
  11313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11314. {
  11315. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11316. }
  11317. else
  11318. {
  11319. tempIndex = connectorIdInt -1;
  11320. }
  11321. for (int index = 0; index < GB_QUANTITY; index++)
  11322. {
  11323. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11324. {
  11325. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11327. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11328. {
  11329. //Reserved
  11330. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11331. }
  11332. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11333. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11334. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11335. {
  11336. //Reserved
  11337. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11339. goto end;
  11340. }
  11341. else
  11342. {
  11343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11346. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11347. {
  11348. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11350. goto end;
  11351. }
  11352. }// END FOR ELSE
  11353. }
  11354. } // END FOR GB_QUANTITY
  11355. }
  11356. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11357. {
  11358. tempIndex = connectorIdInt -1;
  11359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11360. {
  11361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11364. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11365. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11366. {
  11367. //Reserved
  11368. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11369. }
  11370. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11371. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11372. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11373. {
  11374. //Reserved
  11375. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11377. goto end;
  11378. }
  11379. else
  11380. {
  11381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11382. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11383. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11384. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11385. {
  11386. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11388. goto end;
  11389. }
  11390. }// END FOR ELSE
  11391. }
  11392. } // END FOR GB_QUANTITY
  11393. }
  11394. else
  11395. {
  11396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11397. {
  11398. tempIndex = 2;
  11399. }
  11400. else
  11401. {
  11402. tempIndex = connectorIdInt -1;
  11403. }
  11404. for (int index = 0; index < AC_QUANTITY; index++)
  11405. {
  11406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11407. {
  11408. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11409. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11410. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11411. {
  11412. //Reserved
  11413. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11414. }
  11415. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11416. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11417. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11418. {
  11419. //Reserved
  11420. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11421. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11422. goto end;
  11423. }
  11424. else
  11425. {
  11426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11427. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11428. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11429. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11430. {
  11431. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11433. goto end;
  11434. }
  11435. }//END FOR ELSE
  11436. }
  11437. }// END FOR AC_QUANTITY
  11438. }
  11439. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11440. {
  11441. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11442. {
  11443. // Save profile to file
  11444. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11445. system(cmdBuf);
  11446. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11447. fp = fopen(cmdBuf, "w");
  11448. 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));
  11449. fclose(fp);
  11450. }
  11451. else
  11452. {
  11453. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11454. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11455. goto end;
  11456. }
  11457. }
  11458. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11460. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11461. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11462. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11463. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11464. }
  11465. else
  11466. {
  11467. uint8_t isHasIdleConnector = FALSE;
  11468. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11469. {
  11470. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11471. {
  11472. isHasIdleConnector = TRUE;
  11473. break;
  11474. }
  11475. }
  11476. if(isHasIdleConnector == TRUE)
  11477. {
  11478. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11479. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11480. {
  11481. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11482. {
  11483. // Save profile to file
  11484. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11485. system(cmdBuf);
  11486. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11487. fp = fopen(cmdBuf, "w");
  11488. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11489. fclose(fp);
  11490. refreshStartTimer(&clientTime.RemoteStartWait);
  11491. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11492. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11493. }
  11494. else
  11495. {
  11496. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11498. }
  11499. }
  11500. else
  11501. {
  11502. refreshStartTimer(&clientTime.RemoteStartWait);
  11503. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11504. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11505. }
  11506. }
  11507. else
  11508. {
  11509. DEBUG_INFO("There is not any connector is idle.\n");
  11510. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11511. }
  11512. }
  11513. }
  11514. else
  11515. {
  11516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11517. }
  11518. end:
  11519. json_object_put(RemoteStartTransaction);
  11520. sendRemoteStartConfirmation(uuid, comfirmstr);
  11521. return result;
  11522. }
  11523. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11524. {
  11525. mtrace();
  11526. int result = FAIL;
  11527. int match = FALSE;
  11528. int GunNO = 0;
  11529. int tempIndex = 0;
  11530. int transactionIdInt=0;
  11531. int transactionIdIsNULL= TRUE;
  11532. char comfirmstr[20];
  11533. json_object *RemoteStopTransaction;
  11534. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11535. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11536. if(server_pending == TRUE)
  11537. {
  11538. return 0;
  11539. }
  11540. RemoteStopTransaction = json_tokener_parse(payload);
  11541. if(!is_error(RemoteStopTransaction))
  11542. {
  11543. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11544. {
  11545. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11546. transactionIdIsNULL = FALSE;
  11547. }
  11548. }
  11549. json_object_put(RemoteStopTransaction);
  11550. if(transactionIdIsNULL == FALSE)
  11551. {
  11552. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11553. {
  11554. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11555. {
  11556. //check Transaction active
  11557. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11558. {
  11559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11560. {
  11561. tempIndex = ((gun_index==2) ? 1: 0);
  11562. }
  11563. else
  11564. {
  11565. tempIndex = gun_index;
  11566. }
  11567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11568. {
  11569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11570. {
  11571. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11572. {
  11573. match = TRUE;
  11574. GunNO = gun_index;
  11575. }
  11576. }
  11577. }// END FOR CHAdeMO_QUANTITY
  11578. }
  11579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11580. {
  11581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11582. {
  11583. tempIndex = ((gun_index==2) ? 1: 0);
  11584. }
  11585. else
  11586. {
  11587. tempIndex = gun_index;
  11588. }
  11589. for (int index = 0; index < CCS_QUANTITY; index++)
  11590. {
  11591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11592. {
  11593. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11594. {
  11595. match = TRUE;
  11596. GunNO = gun_index;
  11597. }
  11598. }
  11599. }// END FOR CCS_QUANTITY
  11600. }
  11601. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11602. {
  11603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11604. {
  11605. tempIndex = ((gun_index==2) ? 1: 0);
  11606. }
  11607. else
  11608. {
  11609. tempIndex = gun_index;
  11610. }
  11611. for (int index = 0; index < GB_QUANTITY; index++)
  11612. {
  11613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11614. {
  11615. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11616. {
  11617. match = TRUE;
  11618. GunNO = gun_index;
  11619. }
  11620. }
  11621. }// END FOR GB_QUANTITY
  11622. }
  11623. else if(gunType[gun_index] == GUN_TYPE_DO)
  11624. {
  11625. tempIndex = gun_index;
  11626. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11627. {
  11628. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11629. {
  11630. 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
  11631. {
  11632. match = TRUE;
  11633. GunNO = gun_index;
  11634. }
  11635. }
  11636. }// END FOR GB_QUANTITY
  11637. }
  11638. else
  11639. {
  11640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11641. {
  11642. tempIndex = 2;
  11643. }
  11644. else
  11645. {
  11646. tempIndex = gun_index;
  11647. }
  11648. for (int index = 0; index < AC_QUANTITY; index++)
  11649. {
  11650. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11651. {
  11652. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11653. {
  11654. match = TRUE;
  11655. GunNO = gun_index;
  11656. }
  11657. }
  11658. }// END FOR CHAdeMO_QUANTITY
  11659. } // END FOR AC ELSE
  11660. }// CHECK IF ResponseTransactionId == transactionIdInt
  11661. }//END FOR
  11662. if( match == TRUE)
  11663. {
  11664. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11666. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11667. }
  11668. else
  11669. {
  11670. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11671. }
  11672. }
  11673. else
  11674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11675. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11676. return result;
  11677. }
  11678. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11679. {
  11680. mtrace();
  11681. int result = FAIL;
  11682. int connectorIdInt=0, reservationIdInt=0;
  11683. int tempIndex = 0;
  11684. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11685. char comfirmstr[20]={0};
  11686. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11687. int c = 0;
  11688. char *loc;
  11689. //char *ptr;
  11690. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11691. strcpy(sstrtemp, stringtrimspace(payload));
  11692. //***(1)connectorId ****/
  11693. c=0;
  11694. loc = strstr(sstrtemp, "connectorId");
  11695. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11696. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11697. {
  11698. sstr[c] = loc[strlen("connectorId")+2+c];
  11699. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11700. c++;
  11701. }
  11702. sstr[c] = '\0';
  11703. connectorIdInt = atoi(sstr);
  11704. //***(2)expiryDate ****/
  11705. loc = strstr(sstrtemp, "expiryDate");
  11706. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11707. c = 0;
  11708. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11709. {
  11710. sstr[c] = loc[3+strlen("expiryDate")+c];
  11711. c++;
  11712. }
  11713. sstr[c] = '\0';
  11714. strcpy(expiryDatestr, sstr);
  11715. //***(3)idTag ****/
  11716. loc = strstr(sstrtemp, "idTag");
  11717. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11718. c = 0;
  11719. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11720. {
  11721. sstr[c] = loc[3+strlen("idTag")+c];
  11722. c++;
  11723. }
  11724. sstr[c] = '\0';
  11725. strcpy(idTagstr, sstr);
  11726. //***(4)parentIdTag ****/
  11727. loc = strstr(sstrtemp, "parentIdTag");
  11728. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11729. c = 0;
  11730. if(loc == NULL)
  11731. {
  11732. strcpy(parentIdTagstr, "");
  11733. }
  11734. else
  11735. {
  11736. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11737. {
  11738. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11739. c++;
  11740. }
  11741. sstr[c] = '\0';
  11742. strcpy(parentIdTagstr, sstr);
  11743. }
  11744. //***(5)reservationId ****/
  11745. c=0;
  11746. loc = strstr(sstrtemp, "reservationId");
  11747. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11748. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11749. {
  11750. sstr[c] = loc[strlen("reservationId")+2+c];
  11751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11752. c++;
  11753. }
  11754. sstr[c] = '\0';
  11755. reservationIdInt = atoi(sstr);
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11757. /*
  11758. enum SYSTEM_STATUS
  11759. {
  11760. SYS_MODE_BOOTING = 0,
  11761. SYS_MODE_IDLE = 1,
  11762. SYS_MODE_AUTHORIZING = 2,
  11763. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11764. SYS_MODE_REASSIGN = 4,
  11765. SYS_MODE_PREPARING = 5,
  11766. SYS_MODE_PREPARE_FOR_EV = 6,
  11767. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11768. SYS_MODE_CHARGING = 8,
  11769. SYS_MODE_TERMINATING = 9,
  11770. SYS_MODE_COMPLETE = 10,
  11771. SYS_MODE_ALARM = 11,
  11772. SYS_MODE_FAULT = 12,
  11773. SYS_MODE_RESERVATION = 13,
  11774. SYS_MODE_BOOKING = 14,
  11775. SYS_MODE_MAINTAIN = 15,
  11776. SYS_MODE_DEBUG = 16,
  11777. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11778. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11779. SYS_MODE_UPDATE = 19
  11780. };
  11781. */
  11782. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11783. {
  11784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11785. goto end;
  11786. }
  11787. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11788. {
  11789. //check Transaction active
  11790. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11791. {
  11792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11793. {
  11794. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11795. }
  11796. else
  11797. {
  11798. tempIndex = connectorIdInt -1;
  11799. }
  11800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11801. {
  11802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11803. {
  11804. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11805. {
  11806. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11807. {
  11808. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11809. {
  11810. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11811. {
  11812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11813. }
  11814. else
  11815. {
  11816. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11818. }
  11819. }
  11820. 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'))
  11821. {
  11822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11823. }
  11824. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11825. {
  11826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11827. }
  11828. else
  11829. {
  11830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11831. }
  11832. }
  11833. 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
  11834. {
  11835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11836. }
  11837. }
  11838. else
  11839. {
  11840. //replace reservation
  11841. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11843. }
  11844. }
  11845. } // END FOR CHAdeMO_QUANTITY
  11846. }
  11847. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11848. {
  11849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11850. {
  11851. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11852. }
  11853. else
  11854. {
  11855. tempIndex = connectorIdInt -1;
  11856. }
  11857. for (int index = 0; index < CCS_QUANTITY; index++)
  11858. {
  11859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11860. {
  11861. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11862. {
  11863. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11864. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11865. {
  11866. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11867. {
  11868. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11869. {
  11870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11871. }
  11872. else
  11873. {
  11874. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11876. }
  11877. }
  11878. 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'))
  11879. {
  11880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11881. }
  11882. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11883. {
  11884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11885. }
  11886. else
  11887. {
  11888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11889. }
  11890. }
  11891. 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
  11892. {
  11893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11894. }
  11895. }
  11896. else
  11897. {
  11898. //replace reservation
  11899. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11901. }
  11902. }
  11903. } // END FOR CCS_QUANTITY
  11904. }
  11905. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11906. {
  11907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11908. {
  11909. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11910. }
  11911. else
  11912. {
  11913. tempIndex = connectorIdInt -1;
  11914. }
  11915. for (int index = 0; index < GB_QUANTITY; index++)
  11916. {
  11917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11918. {
  11919. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11920. {
  11921. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11922. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11923. {
  11924. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11925. {
  11926. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11927. {
  11928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11929. }
  11930. else
  11931. {
  11932. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11934. }
  11935. }
  11936. 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'))
  11937. {
  11938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11939. }
  11940. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11941. {
  11942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11943. }
  11944. else
  11945. {
  11946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11947. }
  11948. }
  11949. 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
  11950. {
  11951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11952. }
  11953. }
  11954. else
  11955. {
  11956. //replace reservation
  11957. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11959. }
  11960. }
  11961. }// END FOR GB_QUANTITY
  11962. }
  11963. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11964. {
  11965. tempIndex = connectorIdInt -1;
  11966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11967. {
  11968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11969. {
  11970. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11971. {
  11972. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11973. 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
  11974. {
  11975. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11976. {
  11977. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11978. {
  11979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11980. }
  11981. else
  11982. {
  11983. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11985. }
  11986. }
  11987. 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'))
  11988. {
  11989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11990. }
  11991. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11992. {
  11993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11994. }
  11995. else
  11996. {
  11997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11998. }
  11999. }
  12000. 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
  12001. {
  12002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12003. }
  12004. }
  12005. else
  12006. {
  12007. //replace reservation
  12008. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12010. }
  12011. }
  12012. }// END FOR GB_QUANTITY
  12013. }
  12014. else
  12015. {
  12016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12017. {
  12018. tempIndex = 2;
  12019. }
  12020. else
  12021. {
  12022. tempIndex = (connectorIdInt -1);
  12023. }
  12024. for (int index = 0; index < AC_QUANTITY; index++)
  12025. {
  12026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12027. {
  12028. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12029. {
  12030. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12031. {
  12032. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12033. {
  12034. 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))
  12035. {
  12036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12037. }
  12038. else
  12039. {
  12040. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12042. }
  12043. }
  12044. 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'))
  12045. {
  12046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12047. }
  12048. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12049. {
  12050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12051. }
  12052. else
  12053. {
  12054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12055. }
  12056. }
  12057. 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
  12058. {
  12059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12060. }
  12061. }
  12062. else
  12063. {
  12064. //replace reservation
  12065. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12067. }
  12068. }
  12069. } // END FOR AC_QUANTITY
  12070. }
  12071. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12072. }
  12073. else if(connectorIdInt == 0)
  12074. {
  12075. //check Transaction active
  12076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12077. {
  12078. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12079. {
  12080. 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'))
  12081. {
  12082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12083. goto end;
  12084. }
  12085. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12086. {
  12087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12088. goto end;
  12089. }
  12090. 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
  12091. {
  12092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12093. goto end;
  12094. }
  12095. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12096. {
  12097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12098. goto end;
  12099. }
  12100. }
  12101. }// END FOR CHAdeMO_QUANTITY
  12102. for (int index = 0; index < CCS_QUANTITY; index++)
  12103. {
  12104. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12105. {
  12106. 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'))
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12109. goto end;
  12110. }
  12111. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12112. {
  12113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12114. goto end;
  12115. }
  12116. 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
  12117. {
  12118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12119. goto end;
  12120. }
  12121. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12122. {
  12123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12124. goto end;
  12125. }
  12126. }
  12127. } // END FOR CCS_QUANTITY
  12128. for (int index = 0; index < GB_QUANTITY; index++)
  12129. {
  12130. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12131. {
  12132. 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'))
  12133. {
  12134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12135. goto end;
  12136. }
  12137. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12138. {
  12139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12140. goto end;
  12141. }
  12142. 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
  12143. {
  12144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12145. goto end;
  12146. }
  12147. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12148. {
  12149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12150. goto end;
  12151. }
  12152. }
  12153. } // END FOR GB_QUANTITY
  12154. for (int index = 0; index < AC_QUANTITY; index++)
  12155. {
  12156. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12157. {
  12158. 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'))
  12159. {
  12160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12161. goto end;
  12162. }
  12163. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12164. {
  12165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12166. goto end;
  12167. }
  12168. 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
  12169. {
  12170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12171. goto end;
  12172. }
  12173. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12174. {
  12175. 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))
  12176. {
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12178. goto end;
  12179. }
  12180. }
  12181. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12182. {
  12183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12184. goto end;
  12185. }
  12186. }
  12187. }// END FOR AC_QUANTITY
  12188. //The connectorId is 0
  12189. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12191. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12192. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12193. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12194. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12195. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12196. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12197. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12198. result = TRUE;
  12199. return result;
  12200. }
  12201. else
  12202. {
  12203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12204. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12205. }
  12206. if(strcmp(comfirmstr,"Accepted") == 0)
  12207. {
  12208. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12209. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12210. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12211. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12212. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12213. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12214. result = TRUE;
  12215. return result;
  12216. }
  12217. end:
  12218. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12219. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12220. return result;
  12221. }
  12222. int handleResetRequest(char *uuid, char *payload)
  12223. {
  12224. mtrace();
  12225. int result = FAIL;
  12226. char sstr[10]={0},sstrtemp[30]={ 0 };
  12227. char typestr[10]={0};
  12228. char comfirmstr[20]={0};
  12229. int c = 0;
  12230. char *loc;
  12231. DEBUG_INFO("handleResetRequest...\n");
  12232. strcpy(sstrtemp, stringtrimspace(payload));
  12233. loc = strstr(sstrtemp, "type");
  12234. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12235. c = 0;
  12236. while (loc[3+strlen("type")+c] != '\"')
  12237. {
  12238. sstr[c] = loc[3+strlen("type")+c];
  12239. c++;
  12240. }
  12241. sstr[c] = '\0';
  12242. strcpy(typestr,sstr);
  12243. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12244. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12245. {
  12246. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12247. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12248. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12249. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12250. }
  12251. else
  12252. {
  12253. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12254. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12255. result = PASS;
  12256. }
  12257. sendResetConfirmation(uuid, comfirmstr);
  12258. return result;
  12259. }
  12260. int handleSendLocalListRequest(char *uuid, char *payload)
  12261. {
  12262. mtrace();
  12263. int result = FAIL;
  12264. char comfirmstr[20];
  12265. int checkState_Faulted = FALSE;
  12266. json_object *SendLocalList;
  12267. DEBUG_INFO("handleSendLocalListRequest...\n");
  12268. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12269. {
  12270. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12271. goto end;
  12272. }
  12273. //check Charge Point state
  12274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12275. {
  12276. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12277. {
  12278. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12279. }
  12280. }
  12281. for (int index = 0; index < CCS_QUANTITY; index++)
  12282. {
  12283. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12284. {
  12285. checkState_Faulted = TRUE; //OCPP Status
  12286. }
  12287. }
  12288. for (int index = 0; index < GB_QUANTITY; index++)
  12289. {
  12290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12291. {
  12292. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12293. }
  12294. }
  12295. //check Charge Point state
  12296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12297. {
  12298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12299. {
  12300. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12301. }
  12302. }
  12303. //check Charge Point state
  12304. for (int index = 0; index < AC_QUANTITY; index++)
  12305. {
  12306. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12307. {
  12308. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12309. }
  12310. }
  12311. if(checkState_Faulted == TRUE)
  12312. {
  12313. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12314. goto end;
  12315. }
  12316. // Parsing payload
  12317. SendLocalList = json_tokener_parse(payload);
  12318. if(!is_error(SendLocalList))
  12319. {
  12320. // Required data
  12321. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12322. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12323. // Optional data
  12324. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12325. {
  12326. //Check UpdateType
  12327. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12328. {
  12329. //Local list full update
  12330. DEBUG_INFO("Local list full update.\n");
  12331. locallistVersion = 0;
  12332. OCPP_getListVerion();
  12333. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12334. {
  12335. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12336. goto end;
  12337. }*/
  12338. OCPP_cleanLocalList();
  12339. }
  12340. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12341. {
  12342. //Local list different update
  12343. DEBUG_INFO("Local list different update.\n");
  12344. locallistVersion = 0;
  12345. OCPP_getListVerion();
  12346. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12347. {
  12348. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12349. goto end;
  12350. }
  12351. }
  12352. else
  12353. {
  12354. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12355. goto end;
  12356. }
  12357. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12358. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12359. {
  12360. 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")));
  12361. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12362. {
  12363. 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")));
  12364. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12365. 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")));
  12366. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12367. 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")));
  12368. }
  12369. // Add to db
  12370. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12371. {
  12372. //Local list full update
  12373. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12374. idx,
  12375. ShmOCPP16Data->SendLocalList.ListVersion,
  12376. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12377. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12380. // update list
  12381. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12382. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12383. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12384. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12385. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12386. }
  12387. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12388. {
  12389. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12390. idx,
  12391. ShmOCPP16Data->SendLocalList.ListVersion,
  12392. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12394. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12395. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12396. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12397. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12398. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12399. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12400. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12401. }
  12402. }
  12403. }
  12404. else
  12405. {
  12406. //Check UpdateType
  12407. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12408. {
  12409. //Local list full update
  12410. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12411. OCPP_cleanLocalList();
  12412. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12413. goto end;
  12414. }
  12415. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12416. {
  12417. //Local list different update
  12418. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12419. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12420. goto end;
  12421. }
  12422. }
  12423. result = PASS;
  12424. }
  12425. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12426. end:
  12427. json_object_put(SendLocalList);
  12428. sendSendLocalListConfirmation(uuid, comfirmstr);
  12429. return result;
  12430. }
  12431. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12432. {
  12433. mtrace();
  12434. int result = FAIL;
  12435. struct StructSetChargingProfile SetProfileReq = {0};
  12436. int tempchargingProfileIdInt;
  12437. int tempstackLevelInt;
  12438. int chargingSchedulePeriodCount = 0;
  12439. char comfirmstr[20]={0};
  12440. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12441. char rmFileCmd[128]={0};
  12442. int profileQuantity = 0;
  12443. int replaceableProfileCnt = 0;
  12444. json_object *SetChargingProfile;
  12445. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12446. SetChargingProfile = json_tokener_parse(payload);
  12447. if(!is_error(SetChargingProfile))
  12448. {
  12449. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12450. {
  12451. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12452. }
  12453. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12454. {
  12455. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12456. {
  12457. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12458. }
  12459. else
  12460. {
  12461. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12462. DEBUG_WARN("Cannot find chargingProfileId field.");
  12463. goto end;
  12464. }
  12465. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12466. {
  12467. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12468. }
  12469. else
  12470. {
  12471. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12472. DEBUG_WARN("Cannot find stackLevel field.");
  12473. goto end;
  12474. }
  12475. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12476. {
  12477. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12478. }
  12479. else
  12480. {
  12481. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12482. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12483. goto end;
  12484. }
  12485. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12486. {
  12487. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12488. }
  12489. else
  12490. {
  12491. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12492. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12493. goto end;
  12494. }
  12495. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12496. {
  12497. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12498. }
  12499. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12500. {
  12501. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12502. }
  12503. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12504. {
  12505. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12506. }
  12507. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12508. {
  12509. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12510. }
  12511. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12512. {
  12513. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12514. {
  12515. 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")));
  12516. }
  12517. else
  12518. {
  12519. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12520. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12521. goto end;
  12522. }
  12523. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12524. {
  12525. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12526. }
  12527. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12528. {
  12529. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12530. }
  12531. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12532. {
  12533. 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")));
  12534. }
  12535. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12536. {
  12537. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12538. if(chargingSchedulePeriodCount <= 10)
  12539. {
  12540. 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++)
  12541. {
  12542. 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)
  12543. {
  12544. 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"));
  12545. }
  12546. else
  12547. {
  12548. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12549. DEBUG_WARN("Cannot find startPeriod field.");
  12550. goto end;
  12551. }
  12552. 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)
  12553. {
  12554. 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"));
  12555. }
  12556. else
  12557. {
  12558. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12559. DEBUG_WARN("Cannot find limit field.");
  12560. goto end;
  12561. }
  12562. 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)
  12563. {
  12564. 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"));
  12565. }
  12566. }
  12567. }
  12568. }
  12569. else
  12570. {
  12571. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12572. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12573. goto end;
  12574. }
  12575. }
  12576. else
  12577. {
  12578. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12579. DEBUG_WARN("Cannot find chargingSchedule field.");
  12580. goto end;
  12581. }
  12582. }
  12583. }
  12584. // Profile periods quantity check
  12585. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12586. {
  12587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12588. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12589. goto end;
  12590. }
  12591. // Check invalid limit
  12592. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12593. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12594. {
  12595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12596. {
  12597. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12598. {
  12599. 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)))) ||
  12600. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12601. {
  12602. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12603. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12604. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12605. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12606. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12607. goto end;
  12608. }
  12609. }
  12610. }
  12611. else
  12612. {
  12613. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12614. {
  12615. 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) ||
  12616. (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)))
  12617. {
  12618. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12619. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12620. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12621. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12622. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12623. goto end;
  12624. }
  12625. }
  12626. }
  12627. }
  12628. // Profile purpose info check
  12629. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12630. {
  12631. FILE *fp;
  12632. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12633. if(SetProfileReq.ConnectorId != 0)
  12634. {
  12635. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12636. DEBUG_WARN("Profile connector id is not 0.\n");
  12637. goto end;
  12638. }
  12639. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12640. if (!fp)
  12641. {
  12642. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12643. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12644. }
  12645. else
  12646. {
  12647. char *line = NULL;
  12648. size_t len = 0;
  12649. while(getline(&line, &len, fp) != -1)
  12650. {
  12651. json_object *obj = NULL;
  12652. obj = json_tokener_parse(line);
  12653. if(is_error(obj))
  12654. {
  12655. DEBUG_ERROR("Parse txProfile from file error.\n");
  12656. }
  12657. else
  12658. {
  12659. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12660. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12661. {
  12662. profileQuantity += 1;
  12663. }
  12664. else
  12665. replaceableProfileCnt += 1;
  12666. }
  12667. }
  12668. }
  12669. fclose(fp);
  12670. }
  12671. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12672. {
  12673. FILE *fp;
  12674. char filename[128]={0};
  12675. int tmpProfileQuantity;
  12676. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12677. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12678. {
  12679. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12680. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12681. goto end;
  12682. }
  12683. if(SetProfileReq.ConnectorId == 0)
  12684. {
  12685. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12686. {
  12687. tmpProfileQuantity = 0;
  12688. memset(filename, 0, ARRAY_SIZE(filename));
  12689. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12690. fp = fopen(filename, "r");
  12691. if (!fp)
  12692. {
  12693. DEBUG_INFO("%s does not create.\n", filename);
  12694. fp = fopen(filename, "w+");
  12695. }
  12696. else
  12697. {
  12698. char *line = NULL;
  12699. size_t len = 0;
  12700. while(getline(&line, &len, fp) != -1)
  12701. {
  12702. json_object *obj = NULL;
  12703. obj = json_tokener_parse(line);
  12704. if(is_error(obj))
  12705. {
  12706. DEBUG_ERROR("Parse txProfile from file error.\n");
  12707. }
  12708. else
  12709. {
  12710. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12711. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12712. {
  12713. tmpProfileQuantity += 1;
  12714. }
  12715. else
  12716. replaceableProfileCnt += 1;
  12717. }
  12718. }
  12719. }
  12720. fclose(fp);
  12721. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12722. }
  12723. }
  12724. else
  12725. {
  12726. memset(filename, 0, ARRAY_SIZE(filename));
  12727. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12728. fp = fopen(filename, "r");
  12729. if (!fp)
  12730. {
  12731. DEBUG_INFO("%s does not create.\n", filename);
  12732. fp = fopen(filename, "w+");
  12733. }
  12734. else
  12735. {
  12736. char *line = NULL;
  12737. size_t len = 0;
  12738. while(getline(&line, &len, fp) != -1)
  12739. {
  12740. json_object *obj = NULL;
  12741. obj = json_tokener_parse(line);
  12742. if(is_error(obj))
  12743. {
  12744. DEBUG_ERROR("Parse txProfile from file error.\n");
  12745. }
  12746. else
  12747. {
  12748. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12749. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12750. {
  12751. profileQuantity += 1;
  12752. }
  12753. else
  12754. replaceableProfileCnt += 1;
  12755. }
  12756. }
  12757. }
  12758. fclose(fp);
  12759. }
  12760. }
  12761. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12762. {
  12763. int isMatchTransactiodId= FALSE;
  12764. FILE *fp;
  12765. char filename[128]={0};
  12766. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12767. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12768. if(SetProfileReq.ConnectorId == 0)
  12769. {
  12770. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12771. DEBUG_WARN("Profile connector id is 0.\n");
  12772. goto end;
  12773. }
  12774. int tempIndex = 0;
  12775. //check Transaction active
  12776. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12777. {
  12778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12779. {
  12780. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12781. }
  12782. else
  12783. {
  12784. tempIndex = SetProfileReq.ConnectorId -1;
  12785. }
  12786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12787. {
  12788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12789. {
  12790. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12802. {
  12803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12804. {
  12805. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12806. }
  12807. else
  12808. {
  12809. tempIndex = SetProfileReq.ConnectorId -1;
  12810. }
  12811. for (int index = 0; index < CCS_QUANTITY; index++)
  12812. {
  12813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12814. {
  12815. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12816. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12817. {
  12818. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12819. {
  12820. isMatchTransactiodId = TRUE;
  12821. break;
  12822. }
  12823. }
  12824. }
  12825. }
  12826. }
  12827. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12828. {
  12829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12830. {
  12831. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12832. }
  12833. else
  12834. {
  12835. tempIndex = SetProfileReq.ConnectorId -1;
  12836. }
  12837. for (int index = 0; index < GB_QUANTITY; index++)
  12838. {
  12839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12840. {
  12841. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12842. {
  12843. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12844. {
  12845. isMatchTransactiodId = TRUE;
  12846. break;
  12847. }
  12848. }
  12849. }
  12850. }
  12851. }
  12852. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12853. {
  12854. tempIndex = SetProfileReq.ConnectorId -1;
  12855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12856. {
  12857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12858. {
  12859. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12860. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12861. {
  12862. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12863. {
  12864. isMatchTransactiodId = TRUE;
  12865. break;
  12866. }
  12867. }
  12868. }
  12869. }
  12870. }
  12871. else
  12872. {
  12873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12874. {
  12875. tempIndex = 2;
  12876. }
  12877. else
  12878. {
  12879. tempIndex = (SetProfileReq.ConnectorId -1);
  12880. }
  12881. for (int index = 0; index < AC_QUANTITY; index++)
  12882. {
  12883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12884. {
  12885. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12886. {
  12887. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12888. {
  12889. isMatchTransactiodId = TRUE;
  12890. break;
  12891. }
  12892. }
  12893. }
  12894. }
  12895. }
  12896. //check Transaction active
  12897. if(isMatchTransactiodId == FALSE)
  12898. {
  12899. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12900. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12901. goto end;
  12902. }
  12903. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12904. {
  12905. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12906. DEBUG_WARN("Connector id is over max gun number.\n");
  12907. goto end;
  12908. }
  12909. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12910. fp = fopen(filename, "r");
  12911. if (!fp)
  12912. {
  12913. DEBUG_INFO("%s does not create.\n", filename);
  12914. fp = fopen(filename, "w+");
  12915. }
  12916. else
  12917. {
  12918. char *line = NULL;
  12919. size_t len = 0;
  12920. while(getline(&line, &len, fp) != -1)
  12921. {
  12922. json_object *obj = NULL;
  12923. obj = json_tokener_parse(line);
  12924. if(is_error(obj))
  12925. {
  12926. DEBUG_ERROR("Parse txProfile from file error.\n");
  12927. }
  12928. else
  12929. {
  12930. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12931. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12932. {
  12933. profileQuantity += 1;
  12934. }
  12935. else
  12936. replaceableProfileCnt += 1;
  12937. }
  12938. }
  12939. }
  12940. fclose(fp);
  12941. }
  12942. // Check ChargeProfileMaxStackLevel
  12943. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12944. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12945. {
  12946. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12947. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12948. goto end;
  12949. }
  12950. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12951. {
  12952. FILE *fp;
  12953. char dataLine[4096]={0};
  12954. char fnametemp[128]={0};
  12955. int tmpProfileQuantity;
  12956. //Check ChargePointMaxProfile.json exit
  12957. profileQuantity = 0;
  12958. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12959. {
  12960. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12961. //Check Charging Profile Count
  12962. tmpProfileQuantity = 0;
  12963. while(fscanf(fp, "%s", dataLine) != EOF)
  12964. {
  12965. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12966. {
  12967. profileQuantity += 1;
  12968. tmpProfileQuantity += 1;
  12969. }
  12970. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12971. }
  12972. fclose(fp);
  12973. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12974. }
  12975. //Check TxDefaultProfile_%d.json
  12976. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12977. {
  12978. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12979. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12980. if((access(fnametemp,F_OK))!=-1)
  12981. {
  12982. fp = fopen(fnametemp, "r");
  12983. //Check Charging Profile Count
  12984. tmpProfileQuantity = 0;
  12985. while(fscanf(fp, "%s", dataLine) != EOF)
  12986. {
  12987. //DEBUG_INFO("word=%s\n",word);
  12988. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12989. {
  12990. profileQuantity += 1;
  12991. tmpProfileQuantity += 1;
  12992. }
  12993. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12994. }
  12995. fclose(fp);
  12996. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12997. }
  12998. }
  12999. //Check TxProfile_%d.json
  13000. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13001. {
  13002. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13003. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13004. if((access(fnametemp,F_OK))!=-1)
  13005. {
  13006. fp = fopen(fnametemp, "r");
  13007. //Check Charging Profile Count
  13008. tmpProfileQuantity = 0;
  13009. while(fscanf(fp, "%s", dataLine) != EOF)
  13010. {
  13011. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13012. {
  13013. profileQuantity += 1;
  13014. tmpProfileQuantity += 1;
  13015. }
  13016. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13017. }
  13018. fclose(fp);
  13019. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13020. }
  13021. }
  13022. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13023. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13024. // To check total Profile quantity
  13025. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13026. {
  13027. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13028. {
  13029. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13030. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13031. goto end;
  13032. }
  13033. }
  13034. else
  13035. {
  13036. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13037. {
  13038. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13039. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13040. goto end;
  13041. }
  13042. }
  13043. }
  13044. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13045. //**********************************Write to File********************************************************/
  13046. {
  13047. FILE *infile;
  13048. FILE *outfile;
  13049. char dataLine[4096]={0};
  13050. char filename[128]={0};
  13051. int chkChar=0;
  13052. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13053. {
  13054. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13055. {
  13056. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13057. }
  13058. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13059. {
  13060. if(SetProfileReq.ConnectorId==0)
  13061. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13062. else
  13063. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13064. }
  13065. else
  13066. {
  13067. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13068. }
  13069. infile = fopen (filename, "r");
  13070. outfile = fopen (tempfile, "w");
  13071. chkChar = fgetc(infile);
  13072. rewind(infile);
  13073. if(chkChar == EOF)
  13074. {
  13075. // Profile is empty
  13076. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13077. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13078. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13079. fclose(infile);
  13080. fclose(outfile);
  13081. sprintf(rmFileCmd,"rm -f %s",filename);
  13082. system(rmFileCmd);
  13083. rename(tempfile, filename);
  13084. }
  13085. else
  13086. {
  13087. // Profile is not empty
  13088. int ChargingProfileAdded = FALSE;
  13089. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13090. {
  13091. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13092. json_object *tmpChargingProfile;
  13093. tmpChargingProfile = json_tokener_parse(dataLine);
  13094. if(!is_error(SetChargingProfile))
  13095. {
  13096. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13097. {
  13098. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13099. {
  13100. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13101. }
  13102. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13103. {
  13104. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13105. }
  13106. }
  13107. }
  13108. json_object_put(tmpChargingProfile);
  13109. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13110. {
  13111. if(ChargingProfileAdded == FALSE)
  13112. {
  13113. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13114. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13115. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13116. ChargingProfileAdded = TRUE;
  13117. }
  13118. }
  13119. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13120. {
  13121. if(ChargingProfileAdded == FALSE)
  13122. {
  13123. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13124. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13125. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13126. ChargingProfileAdded = TRUE;
  13127. }
  13128. }
  13129. else
  13130. {
  13131. fprintf(outfile,"%s\n",dataLine);
  13132. if(ChargingProfileAdded == FALSE)
  13133. {
  13134. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13135. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13136. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13137. ChargingProfileAdded = TRUE;
  13138. }
  13139. }
  13140. } // end of while loop
  13141. fclose(infile);
  13142. fclose(outfile);
  13143. sprintf(rmFileCmd,"rm -f %s",filename);
  13144. system(rmFileCmd);
  13145. rename(tempfile, filename);
  13146. }
  13147. }
  13148. sleep(1);
  13149. result = TRUE;
  13150. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13151. }
  13152. end:
  13153. json_object_put(SetChargingProfile);
  13154. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13155. {
  13156. if(SetProfileReq.ConnectorId == 0)
  13157. {
  13158. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13159. {
  13160. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13161. }
  13162. }
  13163. else
  13164. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13165. }
  13166. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13167. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13168. return result;
  13169. }
  13170. int handleTriggerMessageRequest(char *uuid, char *payload)
  13171. {
  13172. mtrace();
  13173. int result = FAIL;
  13174. int connectorIdIsNULL = FALSE;
  13175. int connectorIdInt =0;
  13176. char sstr[40]={0},sstrtemp[100]={ 0 };
  13177. char requestedMessagestr[40]={0};
  13178. char comfirmstr[20]={0};
  13179. int c = 0;
  13180. char *loc;
  13181. DEBUG_INFO("handleTriggerMessageRequest\n");
  13182. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13183. strcpy(sstrtemp, stringtrimspace(payload));
  13184. c = 0;
  13185. loc = strstr(sstrtemp, "requestedMessage");
  13186. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13187. {
  13188. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13189. c++;
  13190. }
  13191. sstr[c] = '\0';
  13192. strcpy(requestedMessagestr, sstr);
  13193. c = 0;
  13194. loc = strstr(sstrtemp, "connectorId");
  13195. if(loc == NULL)
  13196. {
  13197. connectorIdIsNULL = TRUE;
  13198. }
  13199. else
  13200. {
  13201. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13202. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13203. {
  13204. sstr[c] = loc[strlen("connectorId")+2+c];
  13205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13206. c++;
  13207. }
  13208. sstr[c] = '\0';
  13209. connectorIdInt = atoi(sstr);
  13210. }
  13211. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13212. {
  13213. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13214. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13215. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13216. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13217. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13218. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13219. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13220. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13221. {
  13222. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13223. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13224. return TRUE;
  13225. }
  13226. else
  13227. {
  13228. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13229. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13230. }
  13231. }
  13232. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13233. {
  13234. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13235. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13236. return TRUE;
  13237. }
  13238. //==========================
  13239. // Trigger message
  13240. //==========================
  13241. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13242. {
  13243. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13244. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13245. {
  13246. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13247. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13248. }
  13249. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13250. }
  13251. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13252. {
  13253. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13254. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13255. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13256. }
  13257. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13258. {
  13259. //sendBootNotificationRequest();
  13260. server_sign = FALSE;
  13261. }
  13262. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13263. {
  13264. refreshStartTimer(&clientTime.Heartbeat);
  13265. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13266. }
  13267. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13268. {
  13269. if(connectorIdIsNULL == FALSE)
  13270. {
  13271. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13272. {
  13273. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13274. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13275. }
  13276. }
  13277. else
  13278. {
  13279. for(int idx=0;idx< gunTotalNumber;idx++)
  13280. {
  13281. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13282. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13283. }
  13284. }
  13285. }
  13286. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13287. {
  13288. if(connectorIdIsNULL == FALSE)
  13289. {
  13290. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13291. {
  13292. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13293. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13294. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13295. }
  13296. }
  13297. else
  13298. {
  13299. for(int idx=0;idx< gunTotalNumber;idx++)
  13300. {
  13301. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13302. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13303. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13304. }
  13305. }
  13306. }
  13307. return result;
  13308. }
  13309. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13310. {
  13311. mtrace();
  13312. int result = FAIL;
  13313. int connectorIdInt =0;
  13314. char comfirmstr[20]={0};
  13315. int tempIndex = 0;
  13316. json_object *UnlockConnector;
  13317. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13318. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13319. UnlockConnector = json_tokener_parse(payload);
  13320. if(!is_error(UnlockConnector))
  13321. {
  13322. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13323. {
  13324. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13325. }
  13326. }
  13327. json_object_put(UnlockConnector);
  13328. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13329. if(gunTotalNumber == 0)
  13330. {
  13331. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13332. goto end;
  13333. }
  13334. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13335. {
  13336. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13337. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13338. goto end;
  13339. }
  13340. else
  13341. {
  13342. //check Transaction active
  13343. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13344. {
  13345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13346. {
  13347. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13348. }
  13349. else
  13350. {
  13351. tempIndex = connectorIdInt -1;
  13352. }
  13353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13354. {
  13355. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13356. {
  13357. //stop Transaction
  13358. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13359. }
  13360. }
  13361. }
  13362. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13363. {
  13364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13365. {
  13366. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13367. }
  13368. else
  13369. {
  13370. tempIndex = connectorIdInt -1;
  13371. }
  13372. for (int index = 0; index < CCS_QUANTITY; index++)
  13373. {
  13374. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13375. {
  13376. //stop Transaction
  13377. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13378. }
  13379. }
  13380. }
  13381. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13382. {
  13383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13384. {
  13385. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13386. }
  13387. else
  13388. {
  13389. tempIndex = connectorIdInt -1;
  13390. }
  13391. for (int index = 0; index < GB_QUANTITY; index++)
  13392. {
  13393. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13394. {
  13395. //stop Transaction
  13396. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13397. }
  13398. }
  13399. }
  13400. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13401. {
  13402. tempIndex = connectorIdInt -1;
  13403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13404. {
  13405. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13406. {
  13407. //stop Transaction
  13408. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13409. }
  13410. }
  13411. }
  13412. else
  13413. {
  13414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13415. {
  13416. tempIndex = 2;
  13417. }
  13418. else
  13419. {
  13420. tempIndex = connectorIdInt-1;
  13421. }
  13422. for (int index = 0; index < AC_QUANTITY; index++)
  13423. {
  13424. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13425. {
  13426. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13427. }
  13428. }
  13429. }
  13430. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13431. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13432. result = TRUE;
  13433. return result;
  13434. }
  13435. end:
  13436. //json_object_put(obj); --- remove temporally
  13437. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13438. return result;
  13439. }
  13440. static char UpdateFirmwarepayloadData[300]={0};
  13441. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13442. {
  13443. mtrace();
  13444. int result = FAIL;
  13445. pthread_t t;
  13446. sendUpdateFirmwareConfirmation(uuid);
  13447. memset(UpdateFirmwarepayloadData, 0, 300);
  13448. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13449. if(!interLock.isUpdateFirmwareGoing)
  13450. {
  13451. interLock.isUpdateFirmwareGoing = 1;
  13452. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13453. sleep(1);
  13454. }
  13455. else
  13456. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13457. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13458. return result;
  13459. }
  13460. void *UpdateFirmwareProcess(void *data)
  13461. {
  13462. pthread_detach(pthread_self());
  13463. mtrace();
  13464. int retriesInt =0, retryIntervalInt=0;
  13465. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13466. int port=0;
  13467. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13468. int isSuccess = 0;
  13469. char ftpbuf[1024];
  13470. char temp[1024];
  13471. char * pch;
  13472. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13473. json_object *UpdateFirmware;
  13474. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13475. if(!is_error(UpdateFirmware))
  13476. {
  13477. // Required data
  13478. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13479. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13480. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13481. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13482. // Optional data
  13483. if(json_object_object_get(UpdateFirmware, "retries"))
  13484. {
  13485. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13486. }
  13487. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13488. {
  13489. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13490. }
  13491. }
  13492. json_object_put(UpdateFirmware);
  13493. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13494. memset(path, 0, ARRAY_SIZE(path));
  13495. // Wait retrieveData
  13496. if(strlen(retrieveDatestr) > 10)
  13497. {
  13498. do
  13499. {
  13500. sleep(1);
  13501. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13502. }
  13503. // Ready to download
  13504. system("rm -f /mnt/*");
  13505. if(strncmp(locationstr,"http", 4) == 0)
  13506. {
  13507. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13508. sprintf(ftppath,"/%s", path);
  13509. DEBUG_INFO("locationstr: %s\n", locationstr);
  13510. DEBUG_INFO("protocol: %s\n",protocol);
  13511. DEBUG_INFO("host: %s\n",host);
  13512. DEBUG_INFO("path: %s\n",path);
  13513. DEBUG_INFO("ftppath: %s\n",ftppath);
  13514. int ftppathlen=strlen(ftppath);
  13515. int i=1;
  13516. char filenametemp[50];
  13517. while(i < ftppathlen)
  13518. {
  13519. int len=ftppathlen-i;
  13520. if(ftppath[len]== 47) // '/' ascll code: 47
  13521. {
  13522. DEBUG_INFO("compare '/' all right\n");
  13523. break;
  13524. }
  13525. i=i+1;
  13526. }
  13527. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13528. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13529. filenametemp[i+1] = 0;
  13530. do
  13531. {
  13532. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13533. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13534. sleep(1);
  13535. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13536. if(!isSuccess)
  13537. {
  13538. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13539. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13540. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13541. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13542. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13543. }
  13544. else
  13545. {
  13546. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13547. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13548. }
  13549. retriesInt--;
  13550. }while((isSuccess == 0)&&(retriesInt >= 0));
  13551. }
  13552. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13553. {
  13554. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13555. memset(temp, 0, ARRAY_SIZE(temp));
  13556. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13557. strcpy(ftpbuf, locationstr);
  13558. int ftppathlen=strlen(ftpbuf);
  13559. int i=1;
  13560. char filenametemp[50];
  13561. while(i < ftppathlen)
  13562. {
  13563. int len=ftppathlen-i;
  13564. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13565. {
  13566. DEBUG_INFO(" compare '/' all right\n");
  13567. break;
  13568. }
  13569. i=i+1;
  13570. }
  13571. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13572. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13573. filenametemp[i+1] = 0;
  13574. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13575. pch=strchr(temp,'@');
  13576. if(pch==NULL)
  13577. {
  13578. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13579. protocol, host, &port, path);
  13580. strcpy(user,"anonymous");
  13581. strcpy(password,"");
  13582. }
  13583. else
  13584. {
  13585. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13586. protocol, user, host, &port, path);
  13587. }
  13588. sscanf(host,"%[^/]%s",host1, path1);
  13589. sprintf(ftppath,"%s:/%s", host,path);
  13590. if(port == 0)
  13591. {
  13592. port = 21;
  13593. }
  13594. do
  13595. {
  13596. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13597. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13598. sleep(1);
  13599. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13600. if(!isSuccess)
  13601. {
  13602. //BulldogUtil.sleepMs(interval*1000);
  13603. DEBUG_INFO("Update firmware request and download file fail.\n");
  13604. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13605. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13606. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13607. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13608. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13609. }
  13610. else
  13611. {
  13612. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13613. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13614. }
  13615. retriesInt--;
  13616. }while((!isSuccess)&&(retriesInt >= 0));
  13617. }
  13618. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13619. {
  13620. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13621. memset(temp, 0, ARRAY_SIZE(temp));
  13622. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13623. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13624. int ftppathlen=strlen(ftpbuf);
  13625. int i=1;
  13626. char filenametemp[50];
  13627. while(i < ftppathlen)
  13628. {
  13629. int len=ftppathlen-i;
  13630. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13631. {
  13632. DEBUG_INFO(" compare '/' all right\n");
  13633. break;
  13634. }
  13635. i=i+1;
  13636. }
  13637. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13638. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13639. filenametemp[i+1] = 0;
  13640. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13641. pch=strchr(temp,'@');
  13642. if(pch==NULL)
  13643. {
  13644. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13645. protocol, host, &port, path);
  13646. strcpy(user,"anonymous");
  13647. strcpy(password,"");
  13648. }
  13649. else
  13650. {
  13651. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13652. protocol, user, password, host, &port, path);
  13653. }
  13654. sscanf(host,"%[^/]%s",host1, path1);
  13655. sprintf(ftppath,"%s", path1);
  13656. //DEBUG_INFO("protocol =%s\n",protocol);
  13657. //DEBUG_INFO("user =%s\n",user);
  13658. //DEBUG_INFO("password =%s\n",password);
  13659. //DEBUG_INFO("host1 =%s\n",host1);
  13660. //DEBUG_INFO("port =%d\n",port);
  13661. //DEBUG_INFO("path1 =%s\n",path1);
  13662. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13663. //ftpFile(host, user, password, port, ftppath, fname);
  13664. //download firmware pthred
  13665. if(port == 0)
  13666. {
  13667. port = 21;
  13668. }
  13669. do
  13670. {
  13671. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13672. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13673. sleep(1);
  13674. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13675. if(!isSuccess)
  13676. {
  13677. //BulldogUtil.sleepMs(interval*1000);
  13678. DEBUG_INFO("Update firmware request and download file fail.\n");
  13679. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13680. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13681. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13682. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13684. }
  13685. else
  13686. {
  13687. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13688. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13689. }
  13690. retriesInt--;
  13691. }while((!isSuccess)&&(retriesInt >= 0));
  13692. }
  13693. else
  13694. {
  13695. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13696. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13697. sleep(1);
  13698. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13699. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13700. }
  13701. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13702. interLock.isUpdateFirmwareGoing = 0;
  13703. pthread_exit(NULL);
  13704. }
  13705. int handleCertificateSignedRequest(char *uuid, char *payload)
  13706. {
  13707. mtrace();
  13708. int result = PASS;
  13709. json_object *CertificateSigned;
  13710. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13711. CertificateSigned = json_tokener_parse(payload);
  13712. if(!is_error(CertificateSigned))
  13713. {
  13714. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13715. }
  13716. json_object_put(CertificateSigned);
  13717. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13718. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13719. fclose(fp);
  13720. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13721. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13722. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13723. sendCertificateSignedConfirmation(uuid);
  13724. return result;
  13725. }
  13726. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13727. {
  13728. mtrace();
  13729. int result = PASS;
  13730. json_object *DeleteCertificate;
  13731. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13732. DeleteCertificate = json_tokener_parse(payload);
  13733. if(!is_error(DeleteCertificate))
  13734. {
  13735. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13736. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13737. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13738. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13739. }
  13740. json_object_put(DeleteCertificate);
  13741. /*
  13742. * TODO: Delete certificateSigned process
  13743. */
  13744. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13745. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13746. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13747. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13748. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13749. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13750. sendDeleteCertificateConfirmation(uuid);
  13751. return result;
  13752. }
  13753. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13754. {
  13755. mtrace();
  13756. int result = PASS;
  13757. json_object *ExtendedTriggerMessage;
  13758. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13759. ExtendedTriggerMessage = json_tokener_parse(payload);
  13760. if(!is_error(ExtendedTriggerMessage))
  13761. {
  13762. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13763. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13764. {
  13765. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13766. }
  13767. else
  13768. {
  13769. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13770. }
  13771. }
  13772. json_object_put(ExtendedTriggerMessage);
  13773. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13774. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13775. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13776. {
  13777. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13778. }
  13779. else
  13780. {
  13781. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13782. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13783. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13784. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13785. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13786. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13787. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13788. {
  13789. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13790. }
  13791. else
  13792. {
  13793. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13794. }
  13795. }
  13796. sendExtendedTriggerMessageConfirmation(uuid);
  13797. //==========================
  13798. // Trigger message
  13799. //==========================
  13800. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13801. {
  13802. //sendBootNotificationRequest();
  13803. server_sign = FALSE;
  13804. }
  13805. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13806. {
  13807. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13808. }
  13809. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13810. {
  13811. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13812. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13813. {
  13814. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13815. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13816. }
  13817. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13818. }
  13819. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13820. {
  13821. refreshStartTimer(&clientTime.Heartbeat);
  13822. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13823. }
  13824. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13825. {
  13826. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13827. {
  13828. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13829. }
  13830. else
  13831. {
  13832. for(int idx=0;idx< gunTotalNumber;idx++)
  13833. {
  13834. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13835. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13836. }
  13837. }
  13838. }
  13839. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13840. {
  13841. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13842. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13843. {
  13844. 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\" &");
  13845. }
  13846. }
  13847. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13848. {
  13849. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13850. {
  13851. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13852. }
  13853. else
  13854. {
  13855. for(int idx=0;idx< gunTotalNumber;idx++)
  13856. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13857. }
  13858. }
  13859. return result;
  13860. }
  13861. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13862. {
  13863. mtrace();
  13864. int result = PASS;
  13865. json_object *GetInstalledCertificateIds;
  13866. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13867. GetInstalledCertificateIds = json_tokener_parse(payload);
  13868. if(!is_error(GetInstalledCertificateIds))
  13869. {
  13870. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13871. }
  13872. json_object_put(GetInstalledCertificateIds);
  13873. /*
  13874. * TODO: Return installed certificate process
  13875. */
  13876. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13877. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13878. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13879. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13880. sendGetInstalledCertificateIdsConfirmation(uuid);
  13881. return result;
  13882. }
  13883. int handleGetLogRequest(char *uuid, char *payload)
  13884. {
  13885. mtrace();
  13886. int result = PASS;
  13887. json_object *GetLog;
  13888. DEBUG_INFO("handleGetLogRequest...\n");
  13889. GetLog = json_tokener_parse(payload);
  13890. if(!is_error(GetLog))
  13891. {
  13892. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13893. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13894. if(json_object_object_get(GetLog, "retries") != NULL)
  13895. {
  13896. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13897. }
  13898. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13899. {
  13900. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13901. }
  13902. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13903. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13904. {
  13905. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13906. }
  13907. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13908. {
  13909. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13910. }
  13911. }
  13912. json_object_put(GetLog);
  13913. /*
  13914. * TODO: Upload log process
  13915. */
  13916. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13917. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13918. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13919. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13920. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13921. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13922. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13923. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13924. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13925. sendGetLogConfirmation(uuid);
  13926. return result;
  13927. }
  13928. int handleInstallCertificateRequest(char *uuid, char *payload)
  13929. {
  13930. mtrace();
  13931. int result = PASS;
  13932. json_object *InstallCertificate;
  13933. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13934. InstallCertificate = json_tokener_parse(payload);
  13935. if(!is_error(InstallCertificate))
  13936. {
  13937. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13938. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13939. /*
  13940. * TODO: Install certificate process
  13941. */
  13942. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13943. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13944. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13945. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13946. sendInstallCertificateConfirmation(uuid);
  13947. }
  13948. json_object_put(InstallCertificate);
  13949. return result;
  13950. }
  13951. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13952. {
  13953. mtrace();
  13954. int result = PASS;
  13955. json_object *SignedUpdateFirmware;
  13956. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13957. SignedUpdateFirmware = json_tokener_parse(payload);
  13958. if(!is_error(SignedUpdateFirmware))
  13959. {
  13960. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13961. {
  13962. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13963. }
  13964. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13965. {
  13966. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13967. }
  13968. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13969. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13970. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13971. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13972. {
  13973. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13974. }
  13975. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13976. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13977. }
  13978. json_object_put(SignedUpdateFirmware);
  13979. /*
  13980. * TODO: Upgrade firmware process
  13981. */
  13982. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13983. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13984. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13985. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13986. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13987. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13988. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13989. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13990. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13991. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13992. sendInstallCertificateConfirmation(uuid);
  13993. return result;
  13994. }
  13995. int handleUnknownRequest(char *uuid, char *payload)
  13996. {
  13997. mtrace();
  13998. int result = PASS;
  13999. DEBUG_INFO("handleUnknownRequest...\n");
  14000. sendUnknownConfirmation(uuid);
  14001. result = PASS;
  14002. return result;
  14003. }
  14004. //==========================================
  14005. // Handle server response routine
  14006. //==========================================
  14007. void handleAuthorizeResponse(char *payload, int gun_index)
  14008. {
  14009. mtrace();
  14010. char expiryDatestr[36]={0};
  14011. char parentIdTagstr[21]={0};
  14012. char statusstr[20]={0};
  14013. int expiryDateISNULL=FALSE;
  14014. int parentIdTagISNULL=FALSE;
  14015. DEBUG_INFO("handleAuthorizeResponse...\n");
  14016. json_object *Authorize;
  14017. Authorize = json_tokener_parse(payload);
  14018. if(!is_error(Authorize))
  14019. {
  14020. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14021. {
  14022. // Required data
  14023. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14024. // Optional data
  14025. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14026. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14027. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14028. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14029. }
  14030. }
  14031. json_object_put(Authorize);
  14032. if(expiryDateISNULL == FALSE)
  14033. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14034. if(parentIdTagISNULL == FALSE)
  14035. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14036. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14037. //Update idTag information to authorization cache if supproted
  14038. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14039. {
  14040. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14041. }
  14042. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14043. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14044. authorizeRetryTimes = 0;
  14045. }
  14046. void handleBootNotificationResponse(char *payload, int gun_index)
  14047. {
  14048. mtrace();
  14049. char statusStr[12]={0};
  14050. char currentTimeStr[30]={0};
  14051. int intervalInt = 0;
  14052. DEBUG_INFO("handleBootNotificationResponse...\n");
  14053. json_object *BootNotification;
  14054. BootNotification = json_tokener_parse(payload);
  14055. if(!is_error(BootNotification))
  14056. {
  14057. // Required data
  14058. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14059. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14060. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14061. }
  14062. json_object_put(BootNotification);
  14063. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14064. BootNotificationInterval = intervalInt;
  14065. //write back to ShmOCPP16Data->BootNotification
  14066. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14067. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14068. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14069. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14070. {
  14071. BootNotificationInterval = 0;
  14072. if((intervalInt == 0) || (intervalInt >= 10))
  14073. {
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14075. HeartBeatWaitTime = intervalInt;
  14076. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14077. }
  14078. server_sign = TRUE;
  14079. server_pending =FALSE;
  14080. }
  14081. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14082. {
  14083. server_pending = TRUE;
  14084. }
  14085. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14086. srand(time(NULL));
  14087. refreshStartTimer(&clientTime.Heartbeat);
  14088. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14089. SetOcppConnStatus(TRUE);
  14090. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14091. }
  14092. void handleDataTransferResponse(char *payload, int gun_index)
  14093. {
  14094. json_object *DataTransfer = json_tokener_parse(payload);
  14095. if(!is_error(DataTransfer))
  14096. {
  14097. // Required data
  14098. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14099. // Optional data
  14100. if(json_object_object_get(DataTransfer, "data") != NULL)
  14101. {
  14102. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14103. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14104. if(!is_error(Data))
  14105. {
  14106. if(json_object_object_get(Data, "msgId") != NULL)
  14107. {
  14108. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14109. {
  14110. 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")));
  14111. }
  14112. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14113. {
  14114. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14115. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14116. }
  14117. }
  14118. }
  14119. json_object_put(Data);
  14120. }
  14121. }
  14122. json_object_put(DataTransfer);
  14123. }
  14124. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14125. {
  14126. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14127. //struct json_object *obj;
  14128. // obj = json_tokener_parse(payload);
  14129. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14130. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14131. //No fields are defined.
  14132. }
  14133. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14134. {
  14135. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14136. //struct json_object *obj;
  14137. // obj = json_tokener_parse(payload);
  14138. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14139. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14140. //No fields are defined.
  14141. }
  14142. void handleHeartbeatResponse(char *payload, int gun_index)
  14143. {
  14144. mtrace();
  14145. DEBUG_INFO("handleHeartbeatResponse...\n");
  14146. json_object *Heartbeat;
  14147. Heartbeat = json_tokener_parse(payload);
  14148. if(!is_error(Heartbeat))
  14149. {
  14150. // Required data
  14151. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14152. }
  14153. json_object_put(Heartbeat);
  14154. if(FirstHeartBeat == 0)
  14155. {
  14156. FirstHeartBeat = 1;
  14157. DEBUG_INFO("FirstHeartBeat \n");
  14158. }
  14159. HeartBeatWithNOResponse = 0;
  14160. refreshStartTimer(&clientTime.Heartbeat);
  14161. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14162. }
  14163. void handleMeterValuesResponse(char *payload, int gun_index)
  14164. {
  14165. mtrace();
  14166. DEBUG_INFO("handleMeterValuesResponse...\n");
  14167. isQueueSendable = 1;
  14168. }
  14169. void handleStartTransactionResponse(char *payload, int gun_index)
  14170. {
  14171. mtrace();
  14172. //int transactionIdInt = 0;
  14173. FILE *outfile;
  14174. char data[100]={0};
  14175. DEBUG_INFO("handleStartTransactionResponse...\n");
  14176. json_object *StartTransaction;
  14177. StartTransaction = json_tokener_parse(payload);
  14178. if(!is_error(StartTransaction))
  14179. {
  14180. // Required data
  14181. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14182. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14183. // Optional data
  14184. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14185. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14186. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14187. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14188. }
  14189. json_object_put(StartTransaction);
  14190. isQueueSendable = 1;
  14191. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14192. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14193. //-----------Start : write to the Queue TransactionId file -----------------//
  14194. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14195. {}
  14196. else
  14197. {
  14198. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14199. if(log == NULL)
  14200. {
  14201. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14202. return ;
  14203. }
  14204. else
  14205. {
  14206. fclose(log);
  14207. }
  14208. }
  14209. // open file for writing
  14210. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14211. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14212. {
  14213. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14214. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14215. fputs(data, outfile);
  14216. fclose (outfile);
  14217. }
  14218. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14219. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14220. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14221. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14222. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14223. }
  14224. void handleStatusNotificationResponse(char *payload, int gun_index)
  14225. {
  14226. mtrace();
  14227. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14228. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14229. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14230. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14231. }
  14232. void handleStopTransactionnResponse(char *payload, int gun_index)
  14233. {
  14234. mtrace();
  14235. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14236. json_object *StopTransaction;
  14237. StopTransaction = json_tokener_parse(payload);
  14238. if(!is_error(StopTransaction))
  14239. {
  14240. // Optional data
  14241. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14242. {
  14243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14244. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14246. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14248. }
  14249. }
  14250. json_object_put(StopTransaction);
  14251. isQueueSendable = 1;
  14252. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14253. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14254. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14255. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14256. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14257. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14258. }
  14259. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14260. {
  14261. mtrace();
  14262. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14263. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14264. }
  14265. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14266. {
  14267. mtrace();
  14268. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14269. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14270. }
  14271. void handleSignCertificateResponse(char *payload, int gun_index)
  14272. {
  14273. mtrace();
  14274. DEBUG_INFO("handleSignCertificateResponse...\n");
  14275. json_object *SignCertificate;
  14276. SignCertificate = json_tokener_parse(payload);
  14277. if(!is_error(SignCertificate))
  14278. {
  14279. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14280. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14281. }
  14282. json_object_put(SignCertificate);
  14283. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14284. }
  14285. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14286. {
  14287. mtrace();
  14288. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14289. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14290. }
  14291. //==========================================
  14292. // Handle Error routine
  14293. //==========================================
  14294. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14295. {
  14296. mtrace();
  14297. #ifdef SystemLogMessage
  14298. DEBUG_INFO("errorCode: %s\n", errorCode);
  14299. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14300. DEBUG_INFO("errorDetails: %s\n", payload);
  14301. #endif
  14302. }
  14303. //===============================================
  14304. // Common routine
  14305. //===============================================
  14306. int initialConfigurationTable(void)
  14307. {
  14308. //clock_t start_t, end_t, total_t;
  14309. FILE *fp;
  14310. FILE *outfile;
  14311. char str[512]={0};
  14312. char sstr[256]={0};
  14313. int c = 0;
  14314. char *loc;
  14315. int confVersion = 15;
  14316. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14317. //start_t = clock();
  14318. //printf("Starting of the program, start_t = %ld\n", start_t);
  14319. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14320. // Check configuration file size is correct
  14321. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14322. {
  14323. struct stat st;
  14324. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14325. if(st.st_size < 3100)
  14326. {
  14327. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14328. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14329. }
  14330. }
  14331. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14332. {
  14333. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14334. if(outfile == NULL)
  14335. {
  14336. DEBUG_INFO("Error opening file\n");
  14337. return FALSE;
  14338. }
  14339. /*Core Profile*/
  14340. //AllowOfflineTxForUnknownId
  14341. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14345. //AuthorizationCacheEnabled
  14346. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14350. //AuthorizeRemoteTxRequests
  14351. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14355. //BlinkRepeat
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14360. //ClockAlignedDataInterval
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14365. //ConnectionTimeOut
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14370. //GetConfigurationMaxKeys
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14375. // HeartbeatInterval
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14380. // LightIntensity
  14381. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14385. // LocalAuthorizeOffline
  14386. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14390. // LocalPreAuthorize
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14395. // MaxEnergyOnInvalidId
  14396. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14400. // MeterValuesAlignedData
  14401. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14404. 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" );
  14405. else
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14408. // MeterValuesAlignedDataMaxLength
  14409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14413. else
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14416. // MeterValuesSampledData
  14417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14420. 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" );
  14421. else
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14424. // MeterValuesSampledDataMaxLength
  14425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14429. else
  14430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14432. // MeterValueSampleInterval
  14433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14437. // MinimumStatusDuration
  14438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14441. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14443. // NumberOfConnectors
  14444. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14447. {
  14448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14449. }
  14450. else
  14451. {
  14452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14453. }
  14454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14455. // ResetRetries
  14456. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14460. // ConnectorPhaseRotation
  14461. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14465. // ConnectorPhaseRotationMaxLength
  14466. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14470. // StopTransactionOnEVSideDisconnect
  14471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14475. // StopTransactionOnInvalidId
  14476. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14480. // StopTxnAlignedData
  14481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14485. // StopTxnAlignedDataMaxLength
  14486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14490. // StopTxnSampledData
  14491. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14495. else
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14498. // StopTxnSampledDataMaxLength
  14499. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14502. {
  14503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14504. }
  14505. else
  14506. {
  14507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14508. }
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14510. // SupportedFeatureProfiles
  14511. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14515. // SupportedFeatureProfilesMaxLength
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14520. // TransactionMessageAttempts
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14524. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14526. // TransactionMessageRetryInterval
  14527. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14530. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14532. // UnlockConnectorOnEVSideDisconnect
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14537. // WebSocketPingInterval
  14538. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14542. // QueueOffLineMeterValues
  14543. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14547. // AuthorizationKey
  14548. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14552. // SecurityProfile
  14553. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14557. // DefaultPrice
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14562. // CustomDisplayCostAndPrice
  14563. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14567. // CustomIdleFeeAfterStop
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14572. // TimeOffset
  14573. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14577. // NextTimeOffsetTransitionDateTime
  14578. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14582. // TimeOffsetNextTransition
  14583. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14587. // SystemUptimeSec
  14588. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14592. // FreeVend
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14597. // FreeVendIdtag
  14598. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14602. // OcppServer
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14605. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14607. // MaintainServer
  14608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14610. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14612. // StatusNotificationPeriodically
  14613. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14617. // StatusNotificationInterval
  14618. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14622. // PreAuthAmount
  14623. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14627. // isEnableLocalPowerSharing
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14632. // PowerSharingServerIP
  14633. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14635. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14637. // EVCCID_PREFIX
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14642. // Configuration Version
  14643. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14647. //* Local Auth List Management Profile*/
  14648. #if 0
  14649. //For OCTT Test Case
  14650. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14653. #endif
  14654. #if 1
  14655. //LocalAuthListEnabled
  14656. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14660. #endif
  14661. //LocalAuthListMaxLength
  14662. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14666. //SendLocalListMaxLength
  14667. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14671. //ReserveConnectorZeroSupported
  14672. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14676. //* Smart Charging Profile */
  14677. //ChargeProfileMaxStackLevel
  14678. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14682. // ChargingScheduleAllowedChargingRateUnit
  14683. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14687. // ChargingScheduleMaxPeriods
  14688. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14692. // ConnectorSwitch3to1PhaseSupported
  14693. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14697. // MaxChargingProfilesInstalled
  14698. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14702. fclose(outfile);
  14703. }
  14704. else
  14705. {
  14706. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14707. char keystr[60]={0};
  14708. char readonlystr[10]={0};
  14709. char valuestr[256]={0};
  14710. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14711. if(fp == NULL) {
  14712. DEBUG_INFO("Error opening file");
  14713. return FALSE;
  14714. }
  14715. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14716. {
  14717. //DEBUG_INFO("Get Configuration \n");
  14718. if(strlen(str) > 0)
  14719. {
  14720. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14721. //*************************key*********************************/
  14722. if(strstr(str, "key") != NULL)
  14723. {
  14724. loc = strstr(str, "key");
  14725. c = 0;
  14726. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14727. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14728. {
  14729. sstr[c] = loc[strlen("key")+3+c];
  14730. c++;
  14731. }
  14732. sstr[c] = '\0';
  14733. strcpy(keystr,sstr);
  14734. }
  14735. //*************************readonly*********************************/
  14736. if(strstr(str, "readonly") != NULL)
  14737. {
  14738. loc = strstr(str, "readonly");
  14739. c = 0;
  14740. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14741. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14742. {
  14743. sstr[c] = loc[strlen("readonly")+2+c];
  14744. c++;
  14745. }
  14746. sstr[c] = '\0';
  14747. strcpy(readonlystr,sstr);
  14748. }
  14749. //*************************value*********************************/
  14750. if(strstr(str, "value") != NULL)
  14751. {
  14752. loc = strstr(str, "value");
  14753. c = 0;
  14754. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14755. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14756. {
  14757. sstr[c] = loc[strlen("value")+3+c];
  14758. c++;
  14759. }
  14760. sstr[c] = '\0';
  14761. strcpy(valuestr,sstr);
  14762. }
  14763. // DEBUG_INFO("keystr=%s\n",keystr);
  14764. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14765. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14766. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14767. {
  14768. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14769. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14771. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14772. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14773. }
  14774. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14775. {
  14776. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14779. }
  14780. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14781. {
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14784. }
  14785. if(strcmp(keystr, "BlinkRepeat") == 0)
  14786. {
  14787. //Charger.BlinkRepeat = Integer.parseInt(value);
  14788. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14790. }
  14791. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14792. {
  14793. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14795. }
  14796. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14797. {
  14798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14800. }
  14801. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14802. {
  14803. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14805. }
  14806. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14807. {
  14808. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14810. HeartBeatWaitTime = atoi(valuestr);
  14811. }
  14812. if(strcmp(keystr, "LightIntensity") == 0)
  14813. {
  14814. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14816. }
  14817. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14818. {
  14819. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14821. }
  14822. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14823. {
  14824. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14826. }
  14827. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14828. {
  14829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14831. }
  14832. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14833. {
  14834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14836. }
  14837. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14838. {
  14839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14841. }
  14842. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14843. {
  14844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14846. }
  14847. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14848. {
  14849. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14851. }
  14852. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14853. {
  14854. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14856. }
  14857. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14858. {
  14859. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14861. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14862. }
  14863. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14864. {
  14865. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14867. }
  14868. if(strcmp(keystr, "ResetRetries") == 0)
  14869. {
  14870. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14872. }
  14873. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14874. {
  14875. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14877. }
  14878. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14879. {
  14880. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14882. }
  14883. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14884. {
  14885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14887. }
  14888. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14889. {
  14890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14892. }
  14893. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14894. {
  14895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14897. }
  14898. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14899. {
  14900. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14902. }
  14903. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14904. {
  14905. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14907. }
  14908. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14909. {
  14910. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14912. }
  14913. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14914. {
  14915. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14917. }
  14918. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14919. {
  14920. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14922. }
  14923. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14924. {
  14925. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14927. TransactionMessageAttemptsValue = atoi(valuestr);
  14928. }
  14929. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14930. {
  14931. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14933. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14934. }
  14935. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14936. {
  14937. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14939. }
  14940. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14941. {
  14942. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14944. }
  14945. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14946. {
  14947. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14949. }
  14950. if(strcmp(keystr, "AuthorizationKey") == 0)
  14951. {
  14952. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14953. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14955. }
  14956. if(strcmp(keystr, "SecurityProfile") == 0)
  14957. {
  14958. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14960. }
  14961. if(strcmp(keystr, "DefaultPrice") == 0)
  14962. {
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14965. }
  14966. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14967. {
  14968. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14970. }
  14971. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14972. {
  14973. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14975. }
  14976. if(strcmp(keystr, "TimeOffset") == 0)
  14977. {
  14978. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14980. }
  14981. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14982. {
  14983. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14985. }
  14986. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14987. {
  14988. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14990. }
  14991. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14992. {
  14993. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14995. }
  14996. if(strcmp(keystr, "FreeVend") == 0)
  14997. {
  14998. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15000. }
  15001. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15002. {
  15003. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15005. }
  15006. if(strcmp(keystr, "OcppServer") == 0)
  15007. {
  15008. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15009. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15010. }
  15011. if(strcmp(keystr, "MaintainServer") == 0)
  15012. {
  15013. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15014. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15015. }
  15016. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15017. {
  15018. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15020. }
  15021. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15022. {
  15023. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15025. }
  15026. if(strcmp(keystr, "PreAuthAmount") == 0)
  15027. {
  15028. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15030. }
  15031. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15032. {
  15033. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15035. }
  15036. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15037. {
  15038. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15039. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15040. }
  15041. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15042. {
  15043. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15045. }
  15046. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15047. {
  15048. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15050. }
  15051. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15052. {
  15053. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15055. }
  15056. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15057. {
  15058. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15060. }
  15061. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15062. {
  15063. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15065. }
  15066. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15067. {
  15068. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15070. }
  15071. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15072. {
  15073. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15075. }
  15076. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15077. {
  15078. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15080. }
  15081. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15082. {
  15083. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15085. }
  15086. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15087. {
  15088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15090. }
  15091. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15092. {
  15093. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15095. }
  15096. }
  15097. }
  15098. fclose(fp);
  15099. }
  15100. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15101. {
  15102. return PASS;
  15103. }
  15104. else
  15105. {
  15106. return FAIL;
  15107. }
  15108. }
  15109. void StoreConfigurationTable(void)
  15110. {
  15111. FILE *outfile;
  15112. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15113. if(outfile == NULL)
  15114. {
  15115. DEBUG_INFO("Error opening file");
  15116. return ;
  15117. }
  15118. /*Core Profile*/
  15119. //AllowOfflineTxForUnknownId
  15120. /*
  15121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15122. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15125. */
  15126. //DEBUG_INFO("data=%s\n",data);
  15127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15128. //AuthorizationCacheEnabled
  15129. /*
  15130. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15133. */
  15134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15135. //AuthorizeRemoteTxRequests
  15136. /*
  15137. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15140. */
  15141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15142. //BlinkRepeat
  15143. /*
  15144. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15147. */
  15148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15149. //ClockAlignedDataInterval
  15150. /*
  15151. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15154. */
  15155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15156. //ConnectionTimeOut
  15157. /*
  15158. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15161. */
  15162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15163. //GetConfigurationMaxKeys
  15164. /*
  15165. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15168. */
  15169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15170. // HeartbeatInterval
  15171. /*
  15172. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15175. */
  15176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15177. // LightIntensity
  15178. /*
  15179. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15182. */
  15183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15184. // LocalAuthorizeOffline
  15185. /*
  15186. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15189. */
  15190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15191. // LocalPreAuthorize
  15192. /*
  15193. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15196. */
  15197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15198. // MaxEnergyOnInvalidId
  15199. /*
  15200. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15203. */
  15204. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15206. // MeterValuesAlignedData
  15207. /*
  15208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15211. */
  15212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15213. // MeterValuesAlignedDataMaxLength
  15214. /*
  15215. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15218. */
  15219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15220. // MeterValuesSampledData
  15221. /*
  15222. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15225. */
  15226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15227. // MeterValuesSampledDataMaxLength
  15228. /*
  15229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15232. */
  15233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15234. // MeterValueSampleInterval
  15235. /*
  15236. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15239. */
  15240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15241. // MinimumStatusDuration
  15242. /*
  15243. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15246. */
  15247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15248. // NumberOfConnectors
  15249. /*
  15250. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15253. {
  15254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15255. }
  15256. else
  15257. {
  15258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15259. }
  15260. */
  15261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15262. // ResetRetries
  15263. /*
  15264. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15267. */
  15268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15269. // ConnectorPhaseRotation
  15270. /*
  15271. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15274. */
  15275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15276. // ConnectorPhaseRotationMaxLength
  15277. /*
  15278. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15281. */
  15282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15283. // StopTransactionOnEVSideDisconnect
  15284. /*
  15285. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15288. */
  15289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15290. // StopTransactionOnInvalidId
  15291. /*
  15292. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15295. */
  15296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15297. // StopTxnAlignedData
  15298. /*
  15299. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15302. */
  15303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15304. // StopTxnAlignedDataMaxLength
  15305. /*
  15306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15309. */
  15310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15311. // StopTxnSampledData
  15312. /*
  15313. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15316. */
  15317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15318. // StopTxnSampledDataMaxLength
  15319. /*
  15320. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15323. */
  15324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15325. // SupportedFeatureProfiles
  15326. /*
  15327. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15330. */
  15331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15332. // SupportedFeatureProfilesMaxLength
  15333. /*
  15334. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15337. */
  15338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15339. // TransactionMessageAttempts
  15340. /*
  15341. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15344. */
  15345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15346. // TransactionMessageRetryInterval
  15347. /*
  15348. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15351. */
  15352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15353. // UnlockConnectorOnEVSideDisconnect
  15354. /*
  15355. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15358. */
  15359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15360. // WebSocketPingInterval
  15361. /*
  15362. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15365. */
  15366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15367. // QueueOffLineMeterValues
  15368. /*
  15369. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15372. */
  15373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15374. // AuthorizationKey
  15375. /*
  15376. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15379. */
  15380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15381. // SecurityProfile
  15382. /*
  15383. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15386. */
  15387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15388. // DefaultPrice
  15389. /*
  15390. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15393. */
  15394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15395. // CustomDisplayCostAndPrice
  15396. /*
  15397. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15400. */
  15401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15402. // CustomIdleFeeAfterStop
  15403. /*
  15404. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15407. */
  15408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15409. // TimeOffset
  15410. /*
  15411. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15414. */
  15415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15416. // NextTimeOffsetTransitionDateTime
  15417. /*
  15418. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15421. */
  15422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15423. // TimeOffsetNextTransition
  15424. /*
  15425. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15428. */
  15429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15430. // SystemUptimeSec
  15431. /*
  15432. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15435. */
  15436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15437. // FreeVend
  15438. /*
  15439. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15442. */
  15443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15444. // FreeVendIdtag
  15445. /*
  15446. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15449. */
  15450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15451. // OcppServer
  15452. /*
  15453. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15456. */
  15457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15458. // MaintainServer
  15459. /*
  15460. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15463. */
  15464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15465. // StatusNotificationPeriodically
  15466. /*
  15467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15470. */
  15471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15472. // StatusNotificationInterval
  15473. /*
  15474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15477. */
  15478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15479. // PreAuthAmount
  15480. /*
  15481. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15484. */
  15485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15486. // isEnableLocalPowerSharing
  15487. /*
  15488. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15491. */
  15492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15493. // PowerSharingServerIP
  15494. /*
  15495. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15498. */
  15499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15500. // EVCCID_PREFIX
  15501. /*
  15502. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15505. */
  15506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15507. // ConfigurationVersion
  15508. /*
  15509. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15512. */
  15513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15514. //* Local Auth List Management Profile*/
  15515. //LocalAuthListEnabled
  15516. /*
  15517. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15520. */
  15521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15522. //LocalAuthListMaxLength
  15523. /*
  15524. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15527. */
  15528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15529. //SendLocalListMaxLength
  15530. /*
  15531. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15534. */
  15535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15536. //ReserveConnectorZeroSupported
  15537. /*
  15538. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15541. */
  15542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15543. //* Smart Charging Profile */
  15544. //ChargeProfileMaxStackLevel
  15545. /*
  15546. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15549. */
  15550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15551. // ChargingScheduleAllowedChargingRateUnit
  15552. /*
  15553. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15556. */
  15557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15558. // ChargingScheduleMaxPeriods
  15559. /*
  15560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15563. */
  15564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15565. // ConnectorSwitch3to1PhaseSupported
  15566. /*
  15567. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15570. */
  15571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15572. // MaxChargingProfilesInstalled
  15573. /*
  15574. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15577. */
  15578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15579. fclose(outfile);
  15580. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15581. }
  15582. void getKeyValue(char *keyReq)
  15583. {
  15584. int isEmpty = FALSE;
  15585. int isKnowKey = FALSE;
  15586. DEBUG_INFO("keyReq = %s\n", keyReq);
  15587. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15588. isEmpty = TRUE;
  15589. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15594. {
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15596. }
  15597. else
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15600. }
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15602. isKnowKey = TRUE;
  15603. }
  15604. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15609. {
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15611. }
  15612. else
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15615. }
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15617. isKnowKey = TRUE;
  15618. }
  15619. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15620. {
  15621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15624. {
  15625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15626. }
  15627. else
  15628. {
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15630. }
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15632. isKnowKey = TRUE;
  15633. }
  15634. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15635. {
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15639. {
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15641. }
  15642. else
  15643. {
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15645. }
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15647. isKnowKey = TRUE;
  15648. }
  15649. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15650. {
  15651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15654. {
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15656. }
  15657. else
  15658. {
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15660. }
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15662. isKnowKey = TRUE;
  15663. }
  15664. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15665. {
  15666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15669. {
  15670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15671. }
  15672. else
  15673. {
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15675. }
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15677. isKnowKey = TRUE;
  15678. }
  15679. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15680. {
  15681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15684. {
  15685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15686. }
  15687. else
  15688. {
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15690. }
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15692. isKnowKey = TRUE;
  15693. }
  15694. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15695. {
  15696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15699. {
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15701. }
  15702. else
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15705. }
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15707. isKnowKey = TRUE;
  15708. }
  15709. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15710. {
  15711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15714. {
  15715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15716. }
  15717. else
  15718. {
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15720. }
  15721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15722. isKnowKey = TRUE;
  15723. }
  15724. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15725. {
  15726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15729. {
  15730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15731. }
  15732. else
  15733. {
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15735. }
  15736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15737. isKnowKey = TRUE;
  15738. }
  15739. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15740. {
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15744. {
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15746. }
  15747. else
  15748. {
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15750. }
  15751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15752. isKnowKey = TRUE;
  15753. }
  15754. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15755. {
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15759. {
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15765. }
  15766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15767. isKnowKey = TRUE;
  15768. }
  15769. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15774. {
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15776. }
  15777. else
  15778. {
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15780. }
  15781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15782. isKnowKey = TRUE;
  15783. }
  15784. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15791. }
  15792. else
  15793. {
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15795. }
  15796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15797. isKnowKey = TRUE;
  15798. }
  15799. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15806. }
  15807. else
  15808. {
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15810. }
  15811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15812. isKnowKey = TRUE;
  15813. }
  15814. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15819. {
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15821. }
  15822. else
  15823. {
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15825. }
  15826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15827. isKnowKey = TRUE;
  15828. }
  15829. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15834. {
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15836. }
  15837. else
  15838. {
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15840. }
  15841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15842. isKnowKey = TRUE;
  15843. }
  15844. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15849. {
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15851. }
  15852. else
  15853. {
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15855. }
  15856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15857. isKnowKey = TRUE;
  15858. }
  15859. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15860. {
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15864. {
  15865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15866. }
  15867. else
  15868. {
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15870. }
  15871. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15873. isKnowKey = TRUE;
  15874. }
  15875. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15876. {
  15877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15880. {
  15881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15882. }
  15883. else
  15884. {
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15886. }
  15887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15888. isKnowKey = TRUE;
  15889. }
  15890. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15891. {
  15892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15895. {
  15896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15897. }
  15898. else
  15899. {
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15901. }
  15902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15903. isKnowKey = TRUE;
  15904. }
  15905. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15906. {
  15907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15910. {
  15911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15912. }
  15913. else
  15914. {
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15916. }
  15917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15918. isKnowKey = TRUE;
  15919. }
  15920. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15921. {
  15922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15925. {
  15926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15927. }
  15928. else
  15929. {
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15931. }
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15933. isKnowKey = TRUE;
  15934. }
  15935. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15936. {
  15937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15940. {
  15941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15942. }
  15943. else
  15944. {
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15946. }
  15947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15948. isKnowKey = TRUE;
  15949. }
  15950. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15951. {
  15952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15955. {
  15956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15957. }
  15958. else
  15959. {
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15961. }
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15963. isKnowKey = TRUE;
  15964. }
  15965. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15966. {
  15967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15970. {
  15971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15972. }
  15973. else
  15974. {
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15976. }
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15978. isKnowKey = TRUE;
  15979. }
  15980. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15981. {
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15985. {
  15986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15987. }
  15988. else
  15989. {
  15990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15991. }
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15993. isKnowKey = TRUE;
  15994. }
  15995. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15996. {
  15997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16000. {
  16001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16002. }
  16003. else
  16004. {
  16005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16006. }
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16008. isKnowKey = TRUE;
  16009. }
  16010. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16011. {
  16012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16015. {
  16016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16017. }
  16018. else
  16019. {
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16021. }
  16022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16023. isKnowKey = TRUE;
  16024. }
  16025. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16030. {
  16031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16032. }
  16033. else
  16034. {
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16036. }
  16037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16038. isKnowKey = TRUE;
  16039. }
  16040. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16045. {
  16046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16047. }
  16048. else
  16049. {
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16051. }
  16052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16053. isKnowKey = TRUE;
  16054. }
  16055. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16060. {
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16062. }
  16063. else
  16064. {
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16066. }
  16067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16068. isKnowKey = TRUE;
  16069. }
  16070. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16075. {
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16077. }
  16078. else
  16079. {
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16081. }
  16082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16083. isKnowKey = TRUE;
  16084. }
  16085. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16090. {
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16092. }
  16093. else
  16094. {
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16096. }
  16097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16098. isKnowKey = TRUE;
  16099. }
  16100. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16105. {
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16107. }
  16108. else
  16109. {
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16111. }
  16112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16113. isKnowKey = TRUE;
  16114. }
  16115. /*
  16116. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16117. {
  16118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16121. {
  16122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16123. }
  16124. else
  16125. {
  16126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16127. }
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16129. isKnowKey = TRUE;
  16130. }*/
  16131. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16132. {
  16133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16136. {
  16137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16138. }
  16139. else
  16140. {
  16141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16142. }
  16143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16144. isKnowKey = TRUE;
  16145. }
  16146. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16147. {
  16148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16151. {
  16152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16153. }
  16154. else
  16155. {
  16156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16157. }
  16158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16159. isKnowKey = TRUE;
  16160. }
  16161. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16162. {
  16163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16166. {
  16167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16168. }
  16169. else
  16170. {
  16171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16172. }
  16173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16174. isKnowKey = TRUE;
  16175. }
  16176. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16177. {
  16178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16181. {
  16182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16183. }
  16184. else
  16185. {
  16186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16187. }
  16188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16189. isKnowKey = TRUE;
  16190. }
  16191. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16192. {
  16193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16196. {
  16197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16198. }
  16199. else
  16200. {
  16201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16202. }
  16203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16204. isKnowKey = TRUE;
  16205. }
  16206. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16207. {
  16208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16211. {
  16212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16213. }
  16214. else
  16215. {
  16216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16217. }
  16218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16219. isKnowKey = TRUE;
  16220. }
  16221. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16222. {
  16223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16226. {
  16227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16228. }
  16229. else
  16230. {
  16231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16232. }
  16233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16234. isKnowKey = TRUE;
  16235. }
  16236. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16237. {
  16238. struct sysinfo s_info;
  16239. int error = sysinfo(&s_info);
  16240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16243. {
  16244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16245. }
  16246. else
  16247. {
  16248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16249. }
  16250. if(error != 0)
  16251. {
  16252. DEBUG_WARN("System uptime get error: %d\n", error);
  16253. }
  16254. else
  16255. {
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16257. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16258. }
  16259. isKnowKey = TRUE;
  16260. }
  16261. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16262. {
  16263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16266. {
  16267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16268. }
  16269. else
  16270. {
  16271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16272. }
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16274. isKnowKey = TRUE;
  16275. }
  16276. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16277. {
  16278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16281. {
  16282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16283. }
  16284. else
  16285. {
  16286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16287. }
  16288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16289. isKnowKey = TRUE;
  16290. }
  16291. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16292. {
  16293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16296. {
  16297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16298. }
  16299. else
  16300. {
  16301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16302. }
  16303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16304. isKnowKey = TRUE;
  16305. }
  16306. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16307. {
  16308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16311. {
  16312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16313. }
  16314. else
  16315. {
  16316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16317. }
  16318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16319. isKnowKey = TRUE;
  16320. }
  16321. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16322. {
  16323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16326. {
  16327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16328. }
  16329. else
  16330. {
  16331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16332. }
  16333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16334. isKnowKey = TRUE;
  16335. }
  16336. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16337. {
  16338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16341. {
  16342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16343. }
  16344. else
  16345. {
  16346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16347. }
  16348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16349. isKnowKey = TRUE;
  16350. }
  16351. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16352. {
  16353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16356. {
  16357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16358. }
  16359. else
  16360. {
  16361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16362. }
  16363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16364. isKnowKey = TRUE;
  16365. }
  16366. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16367. {
  16368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16371. {
  16372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16373. }
  16374. else
  16375. {
  16376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16377. }
  16378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16379. isKnowKey = TRUE;
  16380. }
  16381. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16382. {
  16383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16386. {
  16387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16388. }
  16389. else
  16390. {
  16391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16392. }
  16393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16394. isKnowKey = TRUE;
  16395. }
  16396. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16397. {
  16398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16401. {
  16402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16403. }
  16404. else
  16405. {
  16406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16407. }
  16408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16409. isKnowKey = TRUE;
  16410. }
  16411. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16412. {
  16413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16416. {
  16417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16418. }
  16419. else
  16420. {
  16421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16422. }
  16423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16424. isKnowKey = TRUE;
  16425. }
  16426. #if 1
  16427. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16428. {
  16429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16431. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16432. {
  16433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16434. }
  16435. else
  16436. {
  16437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16438. }
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16440. isKnowKey = TRUE;
  16441. }
  16442. #endif
  16443. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16444. {
  16445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16447. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16448. {
  16449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16450. }
  16451. else
  16452. {
  16453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16454. }
  16455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16456. isKnowKey = TRUE;
  16457. }
  16458. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16459. {
  16460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16462. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16463. {
  16464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16465. }
  16466. else
  16467. {
  16468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16469. }
  16470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16471. isKnowKey = TRUE;
  16472. }
  16473. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16474. {
  16475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16477. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16478. {
  16479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16480. }
  16481. else
  16482. {
  16483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16484. }
  16485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16486. isKnowKey = TRUE;
  16487. }
  16488. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16489. {
  16490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16492. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16493. {
  16494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16495. }
  16496. else
  16497. {
  16498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16499. }
  16500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16501. isKnowKey = TRUE;
  16502. }
  16503. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16504. {
  16505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16507. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16508. {
  16509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16510. }
  16511. else
  16512. {
  16513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16514. }
  16515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16516. isKnowKey = TRUE;
  16517. }
  16518. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16519. {
  16520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16522. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16523. {
  16524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16525. }
  16526. else
  16527. {
  16528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16529. }
  16530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16531. isKnowKey = TRUE;
  16532. }
  16533. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16534. {
  16535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16537. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16538. {
  16539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16540. }
  16541. else
  16542. {
  16543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16544. }
  16545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16546. isKnowKey = TRUE;
  16547. }
  16548. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16549. {
  16550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16552. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16553. {
  16554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16555. }
  16556. else
  16557. {
  16558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16559. }
  16560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16561. isKnowKey = TRUE;
  16562. }
  16563. //=========================================================
  16564. if(!isEmpty && !isKnowKey)
  16565. {
  16566. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16567. strcpy(unknownkey[UnknownKeynum], keyReq);
  16568. UnknownKeynum = UnknownKeynum + 1;
  16569. }
  16570. }
  16571. void processUnkownKey(void)
  16572. {
  16573. DEBUG_INFO("processUnkownKey...\n");
  16574. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16575. for(int index=0; index < UnknownKeynum; index++)
  16576. {
  16577. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16578. {
  16579. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16580. }
  16581. }
  16582. }
  16583. int setKeyValue(char *key, char *value)
  16584. {
  16585. int isSuccess = NotSupported;
  16586. int check_ascii=0;
  16587. char str[501]={0};
  16588. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16589. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16590. {
  16591. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16593. {
  16594. strcpy(str, (const char*)value);
  16595. for(int i = 0; str[i]; i++){
  16596. str[i] = tolower(str[i]);
  16597. }
  16598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16599. isSuccess = ConfigurationStatus_Accepted;
  16600. }
  16601. else
  16602. {
  16603. isSuccess = ConfigurationStatus_Rejected;
  16604. }
  16605. }
  16606. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16607. {
  16608. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16610. {
  16611. strcpy(str, (const char*)value);
  16612. for(int i = 0; str[i]; i++){
  16613. str[i] = tolower(str[i]);
  16614. }
  16615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16616. isSuccess = ConfigurationStatus_Accepted;
  16617. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16618. }
  16619. else
  16620. {
  16621. isSuccess = ConfigurationStatus_Rejected;
  16622. }
  16623. }
  16624. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16625. {
  16626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16627. {
  16628. strcpy(str, (const char*)value);
  16629. for(int i = 0; str[i]; i++)
  16630. {
  16631. str[i] = tolower(str[i]);
  16632. }
  16633. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16635. isSuccess = ConfigurationStatus_Accepted;
  16636. }
  16637. else
  16638. {
  16639. isSuccess = ConfigurationStatus_Rejected;
  16640. }
  16641. }
  16642. if(strcmp(key, "BlinkRepeat") == 0)
  16643. {
  16644. //Charger.BlinkRepeat = Integer.parseInt(value);
  16645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16646. {
  16647. check_ascii = value[0];
  16648. if( (check_ascii < 48) || (check_ascii > 57) )
  16649. {
  16650. isSuccess = ConfigurationStatus_Rejected;
  16651. }
  16652. else
  16653. {
  16654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16655. isSuccess = ConfigurationStatus_Accepted;
  16656. }
  16657. }
  16658. else
  16659. {
  16660. isSuccess = ConfigurationStatus_Rejected;
  16661. }
  16662. }
  16663. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16664. {
  16665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16666. {
  16667. check_ascii = value[0];
  16668. if( (check_ascii < 48) || (check_ascii > 57) )
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. else
  16673. {
  16674. if((atoi(value) == 0) || (atoi(value) >= 5))
  16675. {
  16676. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16678. isSuccess = ConfigurationStatus_Accepted;
  16679. }
  16680. else
  16681. isSuccess = ConfigurationStatus_Rejected;
  16682. }
  16683. }
  16684. else
  16685. {
  16686. isSuccess = ConfigurationStatus_Rejected;
  16687. }
  16688. }
  16689. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16690. {
  16691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16692. {
  16693. check_ascii = value[0];
  16694. if( (check_ascii < 48) || (check_ascii > 57) )
  16695. {
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. else
  16699. {
  16700. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16702. isSuccess = ConfigurationStatus_Accepted;
  16703. }
  16704. }
  16705. else
  16706. {
  16707. isSuccess = ConfigurationStatus_Rejected;
  16708. }
  16709. }
  16710. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16711. {
  16712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16713. {
  16714. check_ascii = value[0];
  16715. if( (check_ascii < 48) || (check_ascii > 57) )
  16716. {
  16717. isSuccess = ConfigurationStatus_Rejected;
  16718. }
  16719. else
  16720. {
  16721. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16723. isSuccess = ConfigurationStatus_Accepted;
  16724. }
  16725. }
  16726. else
  16727. {
  16728. isSuccess = ConfigurationStatus_Rejected;
  16729. }
  16730. }
  16731. if(strcmp(key, "HeartbeatInterval") == 0)
  16732. {
  16733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16734. {
  16735. check_ascii = value[0];
  16736. if( (check_ascii < 48) || (check_ascii > 57) )
  16737. {
  16738. isSuccess = ConfigurationStatus_Rejected;
  16739. }
  16740. else
  16741. {
  16742. if((atoi(value) == 0) || (atoi(value) >= 10))
  16743. {
  16744. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16746. HeartBeatWaitTime = atoi(value);
  16747. isSuccess = ConfigurationStatus_Accepted;
  16748. }
  16749. else
  16750. {
  16751. isSuccess = ConfigurationStatus_Rejected;
  16752. }
  16753. }
  16754. }
  16755. else
  16756. {
  16757. isSuccess = ConfigurationStatus_Rejected;
  16758. }
  16759. }
  16760. if(strcmp(key, "LightIntensity") == 0)
  16761. {
  16762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16763. {
  16764. check_ascii = value[0];
  16765. if( (check_ascii < 48) || (check_ascii > 57) )
  16766. {
  16767. isSuccess = ConfigurationStatus_Rejected;
  16768. }
  16769. else
  16770. {
  16771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16772. isSuccess = ConfigurationStatus_Accepted;
  16773. }
  16774. }
  16775. else
  16776. {
  16777. isSuccess = ConfigurationStatus_Rejected;
  16778. }
  16779. }
  16780. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16781. {
  16782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16783. {
  16784. strcpy(str, (const char*)value);
  16785. for(int i = 0; str[i]; i++)
  16786. {
  16787. str[i] = tolower(str[i]);
  16788. }
  16789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16790. isSuccess = ConfigurationStatus_Accepted;
  16791. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16792. }
  16793. else
  16794. {
  16795. isSuccess = ConfigurationStatus_Rejected;
  16796. }
  16797. }
  16798. if(strcmp(key, "LocalPreAuthorize") == 0)
  16799. {
  16800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16801. {
  16802. strcpy(str, (const char*)value);
  16803. for(int i = 0; str[i]; i++)
  16804. {
  16805. str[i] = tolower(str[i]);
  16806. }
  16807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16808. isSuccess = ConfigurationStatus_Accepted;
  16809. }
  16810. else
  16811. {
  16812. isSuccess = ConfigurationStatus_Rejected;
  16813. }
  16814. }
  16815. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16816. {
  16817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16818. {
  16819. check_ascii = value[0];
  16820. if( (check_ascii < 48) || (check_ascii > 57) )
  16821. {
  16822. isSuccess = ConfigurationStatus_Rejected;
  16823. }
  16824. else
  16825. {
  16826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16827. isSuccess = ConfigurationStatus_Accepted;
  16828. }
  16829. }
  16830. else
  16831. {
  16832. isSuccess = ConfigurationStatus_Rejected;
  16833. }
  16834. }
  16835. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16836. {
  16837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16838. {
  16839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16840. isSuccess = ConfigurationStatus_Accepted;
  16841. }
  16842. else
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. }
  16847. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16848. {
  16849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16850. {
  16851. check_ascii = value[0];
  16852. if( (check_ascii < 48) || (check_ascii > 57) )
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. else
  16857. {
  16858. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16860. isSuccess = ConfigurationStatus_Accepted;
  16861. }
  16862. }
  16863. else
  16864. {
  16865. isSuccess = ConfigurationStatus_Rejected;
  16866. }
  16867. }
  16868. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16869. {
  16870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16871. {
  16872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16873. isSuccess = ConfigurationStatus_Accepted;
  16874. }
  16875. else
  16876. {
  16877. isSuccess = ConfigurationStatus_Rejected;
  16878. }
  16879. }
  16880. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16881. {
  16882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16883. {
  16884. check_ascii = value[0];
  16885. if( (check_ascii < 48) || (check_ascii > 57) )
  16886. {
  16887. isSuccess = ConfigurationStatus_Rejected;
  16888. }
  16889. else
  16890. {
  16891. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16893. isSuccess = ConfigurationStatus_Accepted;
  16894. }
  16895. }
  16896. else
  16897. {
  16898. isSuccess = ConfigurationStatus_Rejected;
  16899. }
  16900. }
  16901. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16902. {
  16903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16904. {
  16905. check_ascii = value[0];
  16906. if( (check_ascii < 48) || (check_ascii > 57) )
  16907. {
  16908. isSuccess = ConfigurationStatus_Rejected;
  16909. }
  16910. else
  16911. {
  16912. if((atoi(value) == 0) || (atoi(value) >= 3))
  16913. {
  16914. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16916. isSuccess = ConfigurationStatus_Accepted;
  16917. }
  16918. else
  16919. {
  16920. isSuccess = ConfigurationStatus_Rejected;
  16921. }
  16922. }
  16923. }
  16924. else
  16925. {
  16926. isSuccess = ConfigurationStatus_Rejected;
  16927. }
  16928. }
  16929. if(strcmp(key, "MinimumStatusDuration") == 0)
  16930. {
  16931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16932. {
  16933. check_ascii = value[0];
  16934. if( (check_ascii < 48) || (check_ascii > 57) )
  16935. {
  16936. isSuccess = ConfigurationStatus_Rejected;
  16937. }
  16938. else
  16939. {
  16940. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16941. {
  16942. isSuccess = ConfigurationStatus_Rejected;
  16943. }
  16944. else
  16945. {
  16946. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16948. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16949. isSuccess = ConfigurationStatus_Accepted;
  16950. }
  16951. }
  16952. }
  16953. else
  16954. {
  16955. isSuccess = ConfigurationStatus_Rejected;
  16956. }
  16957. }
  16958. if(strcmp(key, "NumberOfConnectors") == 0)
  16959. {
  16960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16961. {
  16962. check_ascii = value[0];
  16963. if( (check_ascii < 48) || (check_ascii > 57) )
  16964. {
  16965. isSuccess = ConfigurationStatus_Rejected;
  16966. }
  16967. else
  16968. {
  16969. //Charger.ResetRetries = Integer.parseInt(value);
  16970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16971. isSuccess = ConfigurationStatus_Accepted;
  16972. }
  16973. }
  16974. else
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. }
  16979. if(strcmp(key, "ResetRetries") == 0)
  16980. {
  16981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16982. {
  16983. check_ascii = value[0];
  16984. if( (check_ascii < 48) || (check_ascii > 57) )
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. else
  16989. {
  16990. //Charger.ResetRetries = Integer.parseInt(value);
  16991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16992. isSuccess = ConfigurationStatus_Accepted;
  16993. }
  16994. }
  16995. else
  16996. {
  16997. isSuccess = ConfigurationStatus_Rejected;
  16998. }
  16999. }
  17000. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17001. {
  17002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17003. {
  17004. strcpy(str, (const char*)value);
  17005. for(int i = 0; str[i]; i++)
  17006. {
  17007. str[i] = tolower(str[i]);
  17008. }
  17009. if(strcmp(str, "notapplicable")== 0)
  17010. {
  17011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17012. isSuccess = ConfigurationStatus_Accepted;
  17013. }
  17014. else if(strcmp(str, "unknown")== 0)
  17015. {
  17016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17017. isSuccess = ConfigurationStatus_Accepted;
  17018. }
  17019. else if(strcmp(str, "rst")== 0)
  17020. {
  17021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17022. isSuccess = ConfigurationStatus_Accepted;
  17023. }
  17024. else if(strcmp(str, "rts")== 0)
  17025. {
  17026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17027. isSuccess = ConfigurationStatus_Accepted;
  17028. }
  17029. else if(strcmp(str, "srt")== 0)
  17030. {
  17031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17032. isSuccess = ConfigurationStatus_Accepted;
  17033. }
  17034. else if(strcmp(str, "str")== 0)
  17035. {
  17036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17037. isSuccess = ConfigurationStatus_Accepted;
  17038. }
  17039. else if(strcmp(str, "trs")== 0)
  17040. {
  17041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17042. isSuccess = ConfigurationStatus_Accepted;
  17043. }
  17044. else if(strcmp(str, "tsr")== 0)
  17045. {
  17046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17047. isSuccess = ConfigurationStatus_Accepted;
  17048. }
  17049. else
  17050. {
  17051. isSuccess = ConfigurationStatus_Rejected;
  17052. }
  17053. }
  17054. else
  17055. {
  17056. isSuccess = ConfigurationStatus_Rejected;
  17057. }
  17058. }
  17059. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17060. {
  17061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17062. {
  17063. check_ascii = value[0];
  17064. if( (check_ascii < 48) || (check_ascii > 57) )
  17065. {
  17066. isSuccess = ConfigurationStatus_Rejected;
  17067. }
  17068. else
  17069. {
  17070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17071. isSuccess = ConfigurationStatus_Accepted;
  17072. }
  17073. }
  17074. else
  17075. {
  17076. isSuccess = ConfigurationStatus_Rejected;
  17077. }
  17078. }
  17079. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17080. {
  17081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17082. {
  17083. strcpy(str, (const char*)value);
  17084. for(int i = 0; str[i]; i++)
  17085. {
  17086. str[i] = tolower(str[i]);
  17087. }
  17088. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17090. isSuccess = ConfigurationStatus_Accepted;
  17091. }
  17092. else
  17093. {
  17094. isSuccess = ConfigurationStatus_Rejected;
  17095. }
  17096. }
  17097. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17098. {
  17099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17100. {
  17101. strcpy(str, (const char*)value);
  17102. for(int i = 0; str[i]; i++)
  17103. {
  17104. str[i] = tolower(str[i]);
  17105. }
  17106. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17108. isSuccess = ConfigurationStatus_Accepted;
  17109. }
  17110. else
  17111. {
  17112. isSuccess = ConfigurationStatus_Rejected;
  17113. }
  17114. }
  17115. if(strcmp(key, "StopTxnAlignedData") == 0)
  17116. {
  17117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17118. {
  17119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17120. isSuccess = ConfigurationStatus_Accepted;
  17121. }
  17122. else
  17123. {
  17124. isSuccess = ConfigurationStatus_Rejected;
  17125. }
  17126. }
  17127. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17128. {
  17129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17130. {
  17131. check_ascii = value[0];
  17132. if( (check_ascii < 48) || (check_ascii > 57) )
  17133. {
  17134. isSuccess = ConfigurationStatus_Rejected;
  17135. }
  17136. else
  17137. {
  17138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17139. isSuccess = ConfigurationStatus_Accepted;
  17140. }
  17141. }
  17142. else
  17143. {
  17144. isSuccess = ConfigurationStatus_Rejected;
  17145. }
  17146. }
  17147. if(strcmp(key, "StopTxnSampledData") == 0)
  17148. {
  17149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17150. {
  17151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17152. isSuccess = ConfigurationStatus_Accepted;
  17153. }
  17154. else
  17155. {
  17156. isSuccess = ConfigurationStatus_Rejected;
  17157. }
  17158. }
  17159. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17160. {
  17161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17162. {
  17163. check_ascii = value[0];
  17164. if( (check_ascii < 48) || (check_ascii > 57) )
  17165. {
  17166. isSuccess = ConfigurationStatus_Rejected;
  17167. }
  17168. else
  17169. {
  17170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17171. isSuccess = ConfigurationStatus_Accepted;
  17172. }
  17173. }
  17174. else
  17175. {
  17176. isSuccess = ConfigurationStatus_Rejected;
  17177. }
  17178. }
  17179. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17180. {
  17181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17182. {
  17183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17184. isSuccess = ConfigurationStatus_Accepted;
  17185. }
  17186. else
  17187. {
  17188. isSuccess = ConfigurationStatus_Rejected;
  17189. }
  17190. }
  17191. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17192. {
  17193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17194. {
  17195. check_ascii = value[0];
  17196. if( (check_ascii < 48) || (check_ascii > 57) )
  17197. {
  17198. isSuccess = ConfigurationStatus_Rejected;
  17199. }
  17200. else
  17201. {
  17202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17203. isSuccess = ConfigurationStatus_Accepted;
  17204. }
  17205. }
  17206. else
  17207. {
  17208. isSuccess = ConfigurationStatus_Rejected;
  17209. }
  17210. }
  17211. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17212. {
  17213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17214. {
  17215. check_ascii = value[0];
  17216. if( (check_ascii < 48) || (check_ascii > 57) )
  17217. {
  17218. isSuccess = ConfigurationStatus_Rejected;
  17219. }
  17220. else
  17221. {
  17222. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17224. TransactionMessageAttemptsValue = atoi(value);
  17225. isSuccess = ConfigurationStatus_Accepted;
  17226. }
  17227. }
  17228. else
  17229. {
  17230. isSuccess = ConfigurationStatus_Rejected;
  17231. }
  17232. }
  17233. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17234. {
  17235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17236. {
  17237. check_ascii = value[0];
  17238. if( (check_ascii < 48) || (check_ascii > 57) )
  17239. {
  17240. isSuccess = ConfigurationStatus_Rejected;
  17241. }
  17242. else
  17243. {
  17244. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17246. TransactionMessageRetryIntervalValue = atoi(value);
  17247. isSuccess = ConfigurationStatus_Accepted;
  17248. }
  17249. }
  17250. else
  17251. {
  17252. isSuccess = ConfigurationStatus_Rejected;
  17253. }
  17254. }
  17255. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17256. {
  17257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17258. {
  17259. strcpy(str, (const char*)value);
  17260. for(int i = 0; str[i]; i++)
  17261. {
  17262. str[i] = tolower(str[i]);
  17263. }
  17264. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17266. isSuccess = ConfigurationStatus_Accepted;
  17267. }
  17268. else
  17269. {
  17270. isSuccess = ConfigurationStatus_Rejected;
  17271. }
  17272. }
  17273. if(strcmp(key, "WebSocketPingInterval") == 0)
  17274. {
  17275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17276. {
  17277. check_ascii = value[0];
  17278. if( (check_ascii < 48) || (check_ascii > 57) )
  17279. {
  17280. isSuccess = ConfigurationStatus_Rejected;
  17281. }
  17282. else
  17283. {
  17284. if((atoi(value) == 0) || (atoi(value) >= 10))
  17285. {
  17286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17287. isSuccess = ConfigurationStatus_Accepted;
  17288. }
  17289. else
  17290. isSuccess = ConfigurationStatus_Rejected;
  17291. }
  17292. }
  17293. else
  17294. {
  17295. isSuccess = ConfigurationStatus_Rejected;
  17296. }
  17297. }
  17298. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17299. {
  17300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17301. {
  17302. strcpy(str, (const char*)value);
  17303. for(int i = 0; str[i]; i++)
  17304. {
  17305. str[i] = tolower(str[i]);
  17306. }
  17307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17308. isSuccess = ConfigurationStatus_Accepted;
  17309. }
  17310. else
  17311. {
  17312. isSuccess = ConfigurationStatus_Rejected;
  17313. }
  17314. }
  17315. if(strcmp(key, "AuthorizationKey") == 0)
  17316. {
  17317. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17318. {
  17319. strcpy(str, (const char*)value);
  17320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17321. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17322. isSuccess = ConfigurationStatus_Accepted;
  17323. }
  17324. else
  17325. {
  17326. isSuccess = ConfigurationStatus_Rejected;
  17327. }
  17328. }
  17329. if(strcmp(key, "SecurityProfile") == 0)
  17330. {
  17331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17332. {
  17333. check_ascii = value[0];
  17334. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17335. {
  17336. isSuccess = ConfigurationStatus_Rejected;
  17337. }
  17338. else if(check_ascii == 0x33)
  17339. {
  17340. isSuccess = NotSupported;
  17341. }
  17342. else
  17343. {
  17344. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17345. {
  17346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17347. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17348. isSuccess = ConfigurationStatus_Accepted;
  17349. }
  17350. else
  17351. isSuccess = ConfigurationStatus_Rejected;
  17352. }
  17353. }
  17354. else
  17355. {
  17356. isSuccess = ConfigurationStatus_Rejected;
  17357. }
  17358. }
  17359. if(strcmp(key, "DefaultPrice") == 0)
  17360. {
  17361. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17362. {
  17363. strcpy(str, (const char*)value);
  17364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17365. isSuccess = ConfigurationStatus_Accepted;
  17366. }
  17367. else
  17368. {
  17369. isSuccess = ConfigurationStatus_Rejected;
  17370. }
  17371. }
  17372. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17373. {
  17374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17375. {
  17376. strcpy(str, (const char*)value);
  17377. for(int i = 0; str[i]; i++)
  17378. {
  17379. str[i] = tolower(str[i]);
  17380. }
  17381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17382. isSuccess = ConfigurationStatus_Accepted;
  17383. }
  17384. else
  17385. {
  17386. isSuccess = ConfigurationStatus_Rejected;
  17387. }
  17388. }
  17389. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17390. {
  17391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17392. {
  17393. strcpy(str, (const char*)value);
  17394. for(int i = 0; str[i]; i++)
  17395. {
  17396. str[i] = tolower(str[i]);
  17397. }
  17398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17399. isSuccess = ConfigurationStatus_Accepted;
  17400. }
  17401. else
  17402. {
  17403. isSuccess = ConfigurationStatus_Rejected;
  17404. }
  17405. }
  17406. if(strcmp(key, "TimeOffset") == 0)
  17407. {
  17408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17409. {
  17410. strcpy(str, (const char*)value);
  17411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17412. isSuccess = ConfigurationStatus_Accepted;
  17413. }
  17414. else
  17415. {
  17416. isSuccess = ConfigurationStatus_Rejected;
  17417. }
  17418. }
  17419. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17420. {
  17421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17422. {
  17423. strcpy(str, (const char*)value);
  17424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17425. isSuccess = ConfigurationStatus_Accepted;
  17426. }
  17427. else
  17428. {
  17429. isSuccess = ConfigurationStatus_Rejected;
  17430. }
  17431. }
  17432. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17433. {
  17434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17435. {
  17436. strcpy(str, (const char*)value);
  17437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17438. isSuccess = ConfigurationStatus_Accepted;
  17439. }
  17440. else
  17441. {
  17442. isSuccess = ConfigurationStatus_Rejected;
  17443. }
  17444. }
  17445. if(strcmp(key, "SystemUptimeSec") == 0)
  17446. {
  17447. isSuccess = NotSupported;
  17448. }
  17449. if(strcmp(key, "FreeVend") == 0)
  17450. {
  17451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17452. {
  17453. strcpy(str, (const char*)value);
  17454. for(int i = 0; str[i]; i++)
  17455. {
  17456. str[i] = tolower(str[i]);
  17457. }
  17458. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17460. isSuccess = ConfigurationStatus_Accepted;
  17461. }
  17462. else
  17463. {
  17464. isSuccess = ConfigurationStatus_Rejected;
  17465. }
  17466. }
  17467. if(strcmp(key, "FreeVendIdtag") == 0)
  17468. {
  17469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17470. {
  17471. strcpy(str, (const char*)value);
  17472. if(strlen(str) <= 20)
  17473. {
  17474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17475. isSuccess = ConfigurationStatus_Accepted;
  17476. }
  17477. else
  17478. {
  17479. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17480. isSuccess = ConfigurationStatus_Rejected;
  17481. }
  17482. }
  17483. else
  17484. {
  17485. isSuccess = ConfigurationStatus_Rejected;
  17486. }
  17487. }
  17488. if(strcmp(key, "OcppServer") == 0)
  17489. {
  17490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17491. {
  17492. strcpy(str, (const char*)value);
  17493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17494. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17495. isSuccess = ConfigurationStatus_Accepted;
  17496. }
  17497. else
  17498. {
  17499. isSuccess = ConfigurationStatus_Rejected;
  17500. }
  17501. }
  17502. if(strcmp(key, "MaintainServer") == 0)
  17503. {
  17504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17505. {
  17506. strcpy(str, (const char*)value);
  17507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17508. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17509. isSuccess = ConfigurationStatus_Accepted;
  17510. }
  17511. else
  17512. {
  17513. isSuccess = ConfigurationStatus_Rejected;
  17514. }
  17515. }
  17516. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17517. {
  17518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17519. {
  17520. strcpy(str, (const char*)value);
  17521. for(int i = 0; str[i]; i++)
  17522. {
  17523. str[i] = tolower(str[i]);
  17524. }
  17525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17526. isSuccess = ConfigurationStatus_Accepted;
  17527. }
  17528. else
  17529. {
  17530. isSuccess = ConfigurationStatus_Rejected;
  17531. }
  17532. }
  17533. if(strcmp(key, "StatusNotificationInterval") == 0)
  17534. {
  17535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17536. {
  17537. check_ascii = value[0];
  17538. if( (check_ascii < 48) || (check_ascii > 57) )
  17539. {
  17540. isSuccess = ConfigurationStatus_Rejected;
  17541. }
  17542. else
  17543. {
  17544. if((atoi(value) == 0) || (atoi(value) >= 10))
  17545. {
  17546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17547. isSuccess = ConfigurationStatus_Accepted;
  17548. }
  17549. else
  17550. isSuccess = ConfigurationStatus_Rejected;
  17551. }
  17552. }
  17553. else
  17554. {
  17555. isSuccess = ConfigurationStatus_Rejected;
  17556. }
  17557. }
  17558. if(strcmp(key, "PreAuthAmount") == 0)
  17559. {
  17560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17561. {
  17562. check_ascii = value[0];
  17563. if( (check_ascii < 48) || (check_ascii > 57) )
  17564. {
  17565. isSuccess = ConfigurationStatus_Rejected;
  17566. }
  17567. else
  17568. {
  17569. if(atof(value) >= 0)
  17570. {
  17571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17572. isSuccess = ConfigurationStatus_Accepted;
  17573. }
  17574. else
  17575. isSuccess = ConfigurationStatus_Rejected;
  17576. }
  17577. }
  17578. else
  17579. {
  17580. isSuccess = ConfigurationStatus_Rejected;
  17581. }
  17582. }
  17583. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17584. {
  17585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17586. {
  17587. check_ascii = value[0];
  17588. if( (check_ascii < 48) || (check_ascii > 57) )
  17589. {
  17590. isSuccess = ConfigurationStatus_Rejected;
  17591. }
  17592. else
  17593. {
  17594. if(atoi(value) >= 0)
  17595. {
  17596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17597. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17598. isSuccess = ConfigurationStatus_Accepted;
  17599. }
  17600. else
  17601. isSuccess = ConfigurationStatus_Rejected;
  17602. }
  17603. }
  17604. else
  17605. {
  17606. isSuccess = ConfigurationStatus_Rejected;
  17607. }
  17608. }
  17609. if(strcmp(key, "PowerSharingServerIP") == 0)
  17610. {
  17611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17612. {
  17613. strcpy(str, (const char*)value);
  17614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17615. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17616. isSuccess = ConfigurationStatus_Accepted;
  17617. }
  17618. else
  17619. {
  17620. isSuccess = ConfigurationStatus_Rejected;
  17621. }
  17622. }
  17623. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17624. {
  17625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17626. {
  17627. strcpy(str, (const char*)value);
  17628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17629. isSuccess = ConfigurationStatus_Accepted;
  17630. }
  17631. else
  17632. {
  17633. isSuccess = ConfigurationStatus_Rejected;
  17634. }
  17635. }
  17636. #if 0
  17637. //For OCPP Test Case
  17638. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17639. {
  17640. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17641. {
  17642. strcpy(str, (const char*)value);
  17643. for(int i = 0; str[i]; i++)
  17644. {
  17645. str[i] = tolower(str[i]);
  17646. }
  17647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17648. isSuccess = ConfigurationStatus_Accepted;
  17649. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17650. }
  17651. else
  17652. {
  17653. isSuccess = ConfigurationStatus_Rejected;
  17654. }
  17655. }
  17656. #endif
  17657. #if 1
  17658. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17659. {
  17660. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17661. {
  17662. strcpy(str, (const char*)value);
  17663. for(int i = 0; str[i]; i++)
  17664. {
  17665. str[i] = tolower(str[i]);
  17666. }
  17667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17668. isSuccess = ConfigurationStatus_Accepted;
  17669. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17670. }
  17671. else
  17672. {
  17673. isSuccess = ConfigurationStatus_Rejected;
  17674. }
  17675. }
  17676. #endif
  17677. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17678. {
  17679. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17680. {
  17681. check_ascii = value[0];
  17682. if( (check_ascii < 48) || (check_ascii > 57) )
  17683. {
  17684. isSuccess = ConfigurationStatus_Rejected;
  17685. }
  17686. else
  17687. {
  17688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17689. isSuccess = ConfigurationStatus_Accepted;
  17690. }
  17691. }
  17692. else
  17693. {
  17694. isSuccess = ConfigurationStatus_Rejected;
  17695. }
  17696. }
  17697. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17698. {
  17699. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17700. {
  17701. check_ascii = value[0];
  17702. if( (check_ascii < 48) || (check_ascii > 57) )
  17703. {
  17704. isSuccess = ConfigurationStatus_Rejected;
  17705. }
  17706. else
  17707. {
  17708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17709. isSuccess = ConfigurationStatus_Accepted;
  17710. }
  17711. }
  17712. else
  17713. {
  17714. isSuccess = ConfigurationStatus_Rejected;
  17715. }
  17716. }
  17717. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17718. {
  17719. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17720. {
  17721. strcpy(str, (const char*)value);
  17722. for(int i = 0; str[i]; i++)
  17723. {
  17724. str[i] = tolower(str[i]);
  17725. }
  17726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17727. isSuccess = ConfigurationStatus_Accepted;
  17728. }
  17729. else
  17730. {
  17731. isSuccess = ConfigurationStatus_Rejected;
  17732. }
  17733. }
  17734. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17735. {
  17736. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17737. {
  17738. check_ascii = value[0];
  17739. if( (check_ascii < 48) || (check_ascii > 57) )
  17740. {
  17741. isSuccess = ConfigurationStatus_Rejected;
  17742. }
  17743. else
  17744. {
  17745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17746. isSuccess = ConfigurationStatus_Accepted;
  17747. }
  17748. }
  17749. else
  17750. {
  17751. isSuccess = ConfigurationStatus_Rejected;
  17752. }
  17753. }
  17754. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17755. {
  17756. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17757. {
  17758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17759. isSuccess = ConfigurationStatus_Accepted;
  17760. }
  17761. else
  17762. {
  17763. isSuccess = ConfigurationStatus_Rejected;
  17764. }
  17765. }
  17766. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17767. {
  17768. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17769. {
  17770. check_ascii = value[0];
  17771. if( (check_ascii < 48) || (check_ascii > 57) )
  17772. {
  17773. isSuccess = ConfigurationStatus_Rejected;
  17774. }
  17775. else
  17776. {
  17777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17778. isSuccess = ConfigurationStatus_Accepted;
  17779. }
  17780. }
  17781. else
  17782. {
  17783. isSuccess = ConfigurationStatus_Rejected;
  17784. }
  17785. }
  17786. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17787. {
  17788. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17789. {
  17790. strcpy(str, (const char*)value);
  17791. for(int i = 0; str[i]; i++)
  17792. {
  17793. str[i] = tolower(str[i]);
  17794. }
  17795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17796. isSuccess = ConfigurationStatus_Accepted;
  17797. }
  17798. else
  17799. {
  17800. isSuccess = ConfigurationStatus_Rejected;
  17801. }
  17802. }
  17803. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17804. {
  17805. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17806. {
  17807. check_ascii = value[0];
  17808. if( (check_ascii < 48) || (check_ascii > 57) )
  17809. {
  17810. isSuccess = ConfigurationStatus_Rejected;
  17811. }
  17812. else
  17813. {
  17814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17815. isSuccess = ConfigurationStatus_Accepted;
  17816. }
  17817. }
  17818. else
  17819. {
  17820. isSuccess = ConfigurationStatus_Rejected;
  17821. }
  17822. }
  17823. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17824. return isSuccess;
  17825. }
  17826. int TransactionMessageAttemptsGet(void)
  17827. {
  17828. return TransactionMessageAttemptsValue;
  17829. }
  17830. int FirstHeartBeatResponse(void)
  17831. {
  17832. return FirstHeartBeat;
  17833. }
  17834. int TransactionMessageRetryIntervalGet(void)
  17835. {
  17836. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17837. }
  17838. int ReadHttpStatus(int sock)
  17839. {
  17840. //char c;
  17841. char buff[1024]="",*ptr=buff+1;
  17842. int bytes_received, status;
  17843. DEBUG_INFO("Begin Response ..\n");
  17844. while((bytes_received = recv(sock, ptr, 1, 0))){
  17845. if(bytes_received==-1){
  17846. perror("ReadHttpStatus");
  17847. exit(1);
  17848. }
  17849. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17850. ptr++;
  17851. }
  17852. *ptr=0;
  17853. ptr=buff+1;
  17854. sscanf(ptr,"%*s %d ", &status);
  17855. DEBUG_INFO("%s\n",ptr);
  17856. DEBUG_INFO("status=%d\n",status);
  17857. DEBUG_INFO("End Response ..\n");
  17858. return (bytes_received>0)?status:0;
  17859. }
  17860. //the only filed that it parsed is 'Content-Length'
  17861. int ParseHeader(int sock)
  17862. {
  17863. //char c;
  17864. char buff[1024]="",*ptr=buff+4;
  17865. int bytes_received;
  17866. DEBUG_INFO("Begin HEADER ..\n");
  17867. while((bytes_received = recv(sock, ptr, 1, 0))){
  17868. if(bytes_received==-1){
  17869. perror("Parse Header");
  17870. exit(1);
  17871. }
  17872. if(
  17873. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17874. (ptr[-1]=='\r') && (*ptr=='\n' )
  17875. ) break;
  17876. ptr++;
  17877. }
  17878. *ptr=0;
  17879. ptr=buff+4;
  17880. //printf("%s",ptr);
  17881. if(bytes_received){
  17882. ptr=strstr(ptr,"Content-Length:");
  17883. if(ptr){
  17884. sscanf(ptr,"%*s %d",&bytes_received);
  17885. }else
  17886. bytes_received=-1; //unknown size
  17887. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17888. }
  17889. DEBUG_INFO("End HEADER ..\n");
  17890. return bytes_received ;
  17891. }
  17892. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17893. {
  17894. int result = TRUE;
  17895. char rmFileCmd[100]={0};
  17896. char FilePath[100]={0};
  17897. char ftpbuf[200];
  17898. int systemresult;
  17899. sprintf(FilePath,"/mnt/%s",filename);
  17900. system("ping 8.8.8.8 &");
  17901. if((access(FilePath,F_OK))!=-1)
  17902. {
  17903. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17904. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17905. system(rmFileCmd);
  17906. }
  17907. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17908. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17909. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17910. systemresult = system(ftpbuf);
  17911. if(systemresult != 0)
  17912. {
  17913. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17914. result = FALSE;
  17915. }
  17916. system("pkill ping");
  17917. return result;
  17918. }
  17919. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17920. {
  17921. int result = TRUE;
  17922. char rmFileCmd[100]={0};
  17923. char FilePath[100]={0};
  17924. char ftpbuf[200];
  17925. int systemresult;
  17926. sprintf(FilePath,"/mnt/%s",filename);
  17927. system("ping 8.8.8.8 &");
  17928. if((access(FilePath,F_OK))!=-1)
  17929. {
  17930. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17931. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17932. system(rmFileCmd);
  17933. }
  17934. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17935. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17936. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17937. systemresult = system(ftpbuf);
  17938. if(systemresult != 0)
  17939. {
  17940. DEBUG_WARN("scp error!\n");
  17941. result = FALSE;
  17942. }
  17943. system("pkill ping");
  17944. return result;
  17945. }
  17946. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17947. {
  17948. int result = TRUE;
  17949. char rmFileCmd[100]={0};
  17950. char FilePath[100]={0};
  17951. char ftpbuf[200];
  17952. int systemresult;
  17953. sprintf(FilePath,"/mnt/%s",filename);
  17954. system("ping 8.8.8.8 &");
  17955. if((access(FilePath,F_OK))!=-1)
  17956. {
  17957. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17958. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17959. system(rmFileCmd);
  17960. }
  17961. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17962. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17963. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17964. systemresult = system(ftpbuf);
  17965. if(systemresult != 0)
  17966. {
  17967. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17968. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17969. systemresult = system(ftpbuf);
  17970. if(systemresult != 0)
  17971. {
  17972. DEBUG_WARN("FTP download fail!\n");
  17973. result = FALSE;
  17974. }
  17975. }
  17976. system("pkill ping");
  17977. return result;
  17978. }
  17979. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17980. {
  17981. char rmFileCmd[100]={0};
  17982. char FilePath[100]={0};
  17983. char buf[512];
  17984. int systemresult = 0;
  17985. //DEBUG_INFO("filename=%s\n",filename);
  17986. //DEBUG_INFO("url=%s\n",url);
  17987. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17988. if((access(FilePath,F_OK))!=-1)
  17989. {
  17990. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17991. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17992. system(rmFileCmd);
  17993. }
  17994. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17995. if(fp == NULL)
  17996. {
  17997. DEBUG_INFO("log is NULL\n");
  17998. return FALSE;
  17999. }
  18000. else
  18001. {
  18002. fprintf(fp, "%s\n", url);
  18003. fprintf(fp, "%s\n", filename);
  18004. fclose(fp);
  18005. }
  18006. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18007. if(phpFP == NULL)
  18008. {
  18009. DEBUG_INFO("PHP upload fail.\n");
  18010. return FALSE;
  18011. }
  18012. else
  18013. {
  18014. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18015. {
  18016. if(strstr(buf, "result") != NULL)
  18017. {
  18018. sscanf(buf, "result: %d", &systemresult);
  18019. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18020. }
  18021. }
  18022. pclose(phpFP);
  18023. }
  18024. if(systemresult != 1)
  18025. {
  18026. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18027. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18028. if(phpFP == NULL)
  18029. {
  18030. DEBUG_WARN("PHP PUT upload fail.\n");
  18031. return FALSE;
  18032. }
  18033. else
  18034. {
  18035. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18036. {
  18037. if(strstr(buf, "result") != NULL)
  18038. {
  18039. sscanf(buf, "result: %d", &systemresult);
  18040. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18041. }
  18042. }
  18043. pclose(phpFP);
  18044. }
  18045. }
  18046. if(systemresult != 1)
  18047. {
  18048. DEBUG_WARN("PHP PUT upload fail.\n");
  18049. return FALSE;
  18050. }
  18051. return TRUE;
  18052. }
  18053. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18054. {
  18055. int result = FALSE;
  18056. char ftpbuf[200];
  18057. int systemresult;
  18058. /*
  18059. // Domaind name transfer to IP address
  18060. struct hostent* server;
  18061. char *IPbuffer;
  18062. server = gethostbyname(location);
  18063. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18064. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18065. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18066. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18067. systemresult = system(ftpbuf);
  18068. if(systemresult != 0)
  18069. {
  18070. DEBUG_INFO("ftpput error!\n");
  18071. }
  18072. else
  18073. {
  18074. result = TRUE;
  18075. DEBUG_INFO("ftpput OK!\n");
  18076. }
  18077. return result;
  18078. }
  18079. int GetOcppServerURL()
  18080. {
  18081. int result = FALSE;
  18082. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18083. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18084. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18085. struct yuarel url;
  18086. char urlStr[512];
  18087. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18088. {
  18089. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18090. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18091. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18092. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18093. if(yuarel_parse(&url, urlStr) != -1)
  18094. {
  18095. sprintf(OcppProtocol, "%s", url.scheme);
  18096. sprintf(OcppHost, "%s", url.host);
  18097. if(url.path == NULL)
  18098. OcppTempPath[0] = '\0';
  18099. else
  18100. {
  18101. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18102. {
  18103. sprintf(OcppTempPath, "%s/", url.path);
  18104. }
  18105. else
  18106. {
  18107. sprintf(OcppTempPath, "%s", url.path);
  18108. }
  18109. }
  18110. if(url.port == 0)
  18111. {
  18112. if(strcmp(OcppProtocol, "wss") == 0)
  18113. OcppPort = 443;
  18114. else
  18115. OcppPort = 80;
  18116. }
  18117. else
  18118. OcppPort = url.port;
  18119. result = TRUE;
  18120. }
  18121. }
  18122. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18123. {
  18124. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18125. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18126. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18127. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18128. if(yuarel_parse(&url, urlStr) != -1)
  18129. {
  18130. sprintf(OcppProtocol, "%s", url.scheme);
  18131. sprintf(OcppHost, "%s", url.host);
  18132. if(url.path == NULL)
  18133. OcppTempPath[0] = '\0';
  18134. else
  18135. sprintf(OcppTempPath, "%s", url.path);
  18136. if(url.port == 0)
  18137. {
  18138. if(strcmp(OcppProtocol, "wss") == 0)
  18139. OcppPort = 443;
  18140. else
  18141. OcppPort = 80;
  18142. }
  18143. else
  18144. OcppPort = url.port;
  18145. result = TRUE;
  18146. }
  18147. }
  18148. else
  18149. {
  18150. strcpy(OcppHost,"");
  18151. }
  18152. return result;
  18153. }
  18154. int GetOcppPath()
  18155. {
  18156. int result = FALSE;
  18157. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18158. {
  18159. if(OcppTempPath == NULL)
  18160. {
  18161. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18162. }
  18163. else
  18164. {
  18165. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18166. }
  18167. result = TRUE;
  18168. goto End;
  18169. }
  18170. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18171. {
  18172. if(OcppTempPath == NULL)
  18173. {
  18174. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18175. }
  18176. else
  18177. {
  18178. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18179. }
  18180. result = TRUE;
  18181. goto End;
  18182. }
  18183. else
  18184. {
  18185. strcpy(OcppPath,"");
  18186. }
  18187. End:
  18188. return result;
  18189. }
  18190. int GetOcppPort()
  18191. {
  18192. return OcppPort;
  18193. }
  18194. int GetOcppConnStatus(void)
  18195. {
  18196. return ShmOCPP16Data->OcppConnStatus;
  18197. }
  18198. void SetOcppConnStatus(uint8_t status)
  18199. {
  18200. ShmOCPP16Data->OcppConnStatus = status;
  18201. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18202. }
  18203. int GetHeartBeatWithNOResponse(void)
  18204. {
  18205. return HeartBeatWithNOResponse;
  18206. }
  18207. void SetHeartBeatWithNOResponse(void)
  18208. {
  18209. HeartBeatWithNOResponse = 0;
  18210. }
  18211. void GetStartTransactionIdTag(int gun_index)
  18212. {
  18213. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18214. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18215. }
  18216. int GetStartTransactionId(int gun_index)
  18217. {
  18218. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18219. }
  18220. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18221. {
  18222. char ch;
  18223. FILE *fptr1;
  18224. int temptransactionId;
  18225. char str[100]={0};
  18226. temptransactionId = 0;
  18227. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18228. {
  18229. DEBUG_INFO("IdTag is empty.\n");
  18230. return temptransactionId;
  18231. }
  18232. /*------ Read the file ----------------*/
  18233. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18234. if (!fptr1)
  18235. {
  18236. DEBUG_INFO("QueueTransactionId file open error.\n");
  18237. //printf(" File not found or unable to open the input file!!\n");
  18238. return temptransactionId;
  18239. }
  18240. ch=fgetc(fptr1);
  18241. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18242. rewind(fptr1);
  18243. if(ch!=EOF)
  18244. {
  18245. // printf("%c",ch);
  18246. while (fgets(str, 100, fptr1) != NULL)
  18247. {
  18248. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18249. if(str[0]=='\0')
  18250. {
  18251. break;
  18252. }
  18253. char *revbuf[8] = {0}; // Variable store string split
  18254. int num = 0;// Quantity after string split
  18255. DEBUG_INFO("Transaction queue data= %s\n", str);
  18256. splitstring(str,",",revbuf,&num); // String split
  18257. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18258. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18259. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18260. DEBUG_INFO("------------------------------\n");
  18261. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18262. {
  18263. if(isStopTransaction)
  18264. {
  18265. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18266. {
  18267. temptransactionId = atoi(revbuf[2]);
  18268. //break;
  18269. }
  18270. }
  18271. else
  18272. {
  18273. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18274. {
  18275. temptransactionId = atoi(revbuf[2]);
  18276. //break;
  18277. }
  18278. }
  18279. }
  18280. }
  18281. }
  18282. else
  18283. DEBUG_INFO("EOF\n");
  18284. fclose(fptr1);
  18285. /*------- End of reading ---------------*/
  18286. return temptransactionId;
  18287. }
  18288. void SetTransactionIdZero(int transactionId)
  18289. {
  18290. char ch;
  18291. FILE *fptr1, *fptr2;
  18292. int temptransactionId = 0;
  18293. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18294. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18295. if (!fptr1)
  18296. {
  18297. //printf(" File not found or unable to open the input file!!\n");
  18298. return ;
  18299. }
  18300. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18301. if (!fptr2)
  18302. {
  18303. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18304. fclose(fptr1);
  18305. return ;
  18306. }
  18307. ch=fgetc(fptr1);
  18308. rewind(fptr1);
  18309. if(ch!=EOF)
  18310. {
  18311. // copy all contents to the temporary file except the specific line
  18312. while (fgets(str, 100, fptr1) != NULL)
  18313. {
  18314. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18315. if(str[0]=='\0')
  18316. {
  18317. break;
  18318. }
  18319. char *revbuf[8] = {0};
  18320. int num = 0;
  18321. strcpy(strtemp, str);
  18322. splitstring(str,",",revbuf,&num);
  18323. if(revbuf[2][0] != '\0')
  18324. {
  18325. temptransactionId = atoi(revbuf[2]);
  18326. if(transactionId != temptransactionId)
  18327. {
  18328. fprintf(fptr2, "%s\n", strtemp);
  18329. }
  18330. }
  18331. }
  18332. }
  18333. fclose(fptr1);
  18334. fclose(fptr2);
  18335. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18336. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18337. /*------ Read the file ----------------*/
  18338. }
  18339. int InternetDisconnect(void)
  18340. {
  18341. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18342. }
  18343. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18344. void storeTempStopTransaction(int gun_index)
  18345. {
  18346. char guid[37]={0};
  18347. int tempIndex = 0;
  18348. char TempStopTransaction[256];
  18349. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18350. DEBUG_INFO("storeTempStopTransaction...\n");
  18351. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18352. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18353. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18354. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18355. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18356. {
  18357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18358. {
  18359. tempIndex = ((gun_index==2) ? 1: 0);
  18360. }
  18361. else
  18362. {
  18363. tempIndex = gun_index;
  18364. }
  18365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18366. {
  18367. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18368. {
  18369. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18370. }
  18371. }// END OF CHAdeMO_QUANTITY
  18372. }
  18373. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18374. {
  18375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18376. {
  18377. tempIndex = ((gun_index==2) ? 1: 0);
  18378. }
  18379. else
  18380. {
  18381. tempIndex = gun_index;
  18382. }
  18383. for (int index = 0; index < CCS_QUANTITY; index++)
  18384. {
  18385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18386. {
  18387. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18388. }
  18389. }// END OF CCS_QUANTITY
  18390. }
  18391. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18392. {
  18393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18394. {
  18395. tempIndex = ((gun_index==2) ? 1: 0);
  18396. }
  18397. else
  18398. {
  18399. tempIndex = gun_index;
  18400. }
  18401. for (int index = 0; index < GB_QUANTITY; index++)
  18402. {
  18403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18404. {
  18405. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18406. }
  18407. }// END OF GB_QUANTITY
  18408. }
  18409. else if(gunType[gun_index] == GUN_TYPE_DO)
  18410. {
  18411. tempIndex = gun_index;
  18412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18413. {
  18414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18415. {
  18416. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18417. }
  18418. }
  18419. }
  18420. else
  18421. {
  18422. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18423. {
  18424. tempIndex = 2;
  18425. }
  18426. else
  18427. {
  18428. tempIndex = gun_index;
  18429. }
  18430. for (int index = 0; index < AC_QUANTITY; index++)
  18431. {
  18432. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18433. {
  18434. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18435. }
  18436. }// END OF AC_QUANTITY
  18437. }
  18438. //Stop Transaction Time
  18439. struct timeval tmnow;
  18440. struct tm *tm;
  18441. char buf[28];//, usec_buf[6];
  18442. gettimeofday(&tmnow, NULL);
  18443. time_t t;
  18444. t = time(NULL);
  18445. /*UTC time and date*/
  18446. tm = gmtime(&t);
  18447. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18449. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18451. random_uuid(guid);
  18452. /***********************************transactionData******************************************************/
  18453. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18455. //=================================
  18456. //1. Transaction_Begin
  18457. //=================================
  18458. //============================== Energy.Active.Import.Interval ===========================================
  18459. //=================================
  18460. //2. Transaction_End
  18461. //=================================
  18462. //2.1====================================== Current.Import L1 ==============================================
  18463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18464. {
  18465. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18466. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18467. {
  18468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18469. {
  18470. tempIndex = ((gun_index==2) ? 1: 0);
  18471. }
  18472. else
  18473. {
  18474. tempIndex = gun_index;
  18475. }
  18476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18477. {
  18478. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18479. {
  18480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18481. }
  18482. }// End of for CHAdeMO_QUANTITY
  18483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18484. }
  18485. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18486. {
  18487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18488. {
  18489. tempIndex = ((gun_index==2) ? 1: 0);
  18490. }
  18491. else
  18492. {
  18493. tempIndex = gun_index;
  18494. }
  18495. for (int index = 0; index < CCS_QUANTITY; index++)
  18496. {
  18497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18498. {
  18499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18500. }
  18501. }// End of for CCS_QUANTITY
  18502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18503. }
  18504. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18505. {
  18506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18507. {
  18508. tempIndex = ((gun_index==2) ? 1: 0);
  18509. }
  18510. else
  18511. {
  18512. tempIndex = gun_index;
  18513. }
  18514. for (int index = 0; index < GB_QUANTITY; index++)
  18515. {
  18516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18517. {
  18518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18519. }
  18520. }// End of for GB_QUANTITY
  18521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18522. }
  18523. else if(gunType[gun_index] == GUN_TYPE_DO)
  18524. {
  18525. tempIndex = gun_index;
  18526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18527. {
  18528. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18529. {
  18530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18531. }
  18532. }
  18533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18534. }
  18535. else
  18536. {
  18537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18538. {
  18539. tempIndex = 2;
  18540. }
  18541. else
  18542. {
  18543. tempIndex = gun_index;
  18544. }
  18545. for (int index = 0; index < AC_QUANTITY; index++)
  18546. {
  18547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18548. {
  18549. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18550. }
  18551. }// End of for AC_QUANTITY
  18552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18553. }
  18554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18557. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18560. }
  18561. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18562. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18563. {
  18564. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18565. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18566. {
  18567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18568. {
  18569. tempIndex = ((gun_index==2) ? 1: 0);
  18570. }
  18571. else
  18572. {
  18573. tempIndex = gun_index;
  18574. }
  18575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18576. {
  18577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18578. {
  18579. 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
  18580. }
  18581. }// END OF CHAdeMO_QUANTITY
  18582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18583. }
  18584. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18585. {
  18586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18587. {
  18588. tempIndex = ((gun_index==2) ? 1: 0);
  18589. }
  18590. else
  18591. {
  18592. tempIndex = gun_index;
  18593. }
  18594. for (int index = 0; index < CCS_QUANTITY; index++)
  18595. {
  18596. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18597. {
  18598. 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
  18599. }
  18600. }// END OF CCS_QUANTITY
  18601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18602. }
  18603. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18604. {
  18605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18606. {
  18607. tempIndex = ((gun_index==2) ? 1: 0);
  18608. }
  18609. else
  18610. {
  18611. tempIndex = gun_index;
  18612. }
  18613. for (int index = 0; index < GB_QUANTITY; index++)
  18614. {
  18615. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18616. {
  18617. 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
  18618. }
  18619. }// END OF GB_QUANTITY
  18620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18621. }
  18622. else if(gunType[gun_index] == GUN_TYPE_DO)
  18623. {
  18624. tempIndex = gun_index;
  18625. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18626. {
  18627. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18628. {
  18629. 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
  18630. }
  18631. }
  18632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18633. }
  18634. else
  18635. {
  18636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18637. {
  18638. tempIndex = 2;
  18639. }
  18640. else
  18641. {
  18642. tempIndex = gun_index;
  18643. }
  18644. for (int index = 0; index < AC_QUANTITY; index++)
  18645. {
  18646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18647. {
  18648. 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
  18649. }
  18650. }// END OF AC_QUANTITY
  18651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18652. }
  18653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18656. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18659. }
  18660. //2.3====================================== Power.Active.Import =========================================
  18661. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18662. {
  18663. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18664. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18665. {
  18666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18667. {
  18668. tempIndex = ((gun_index==2) ? 1: 0);
  18669. }
  18670. else
  18671. {
  18672. tempIndex = gun_index;
  18673. }
  18674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18675. {
  18676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18677. {
  18678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18679. }
  18680. } // End for CHAdeMO_QUANTITY
  18681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18682. }
  18683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18684. {
  18685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18686. {
  18687. tempIndex = ((gun_index==2) ? 1: 0);
  18688. }
  18689. else
  18690. {
  18691. tempIndex = gun_index;
  18692. }
  18693. for (int index = 0; index < CCS_QUANTITY; index++)
  18694. {
  18695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18696. {
  18697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18698. }
  18699. } // END for CCS_QUANTITY
  18700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18701. }
  18702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18703. {
  18704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18705. {
  18706. tempIndex = ((gun_index==2) ? 1: 0);
  18707. }
  18708. else
  18709. {
  18710. tempIndex = gun_index;
  18711. }
  18712. for (int index = 0; index < GB_QUANTITY; index++)
  18713. {
  18714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18715. {
  18716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18717. }
  18718. }// END for GB_QUANTITY
  18719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18720. }
  18721. else if(gunType[gun_index] == GUN_TYPE_DO)
  18722. {
  18723. tempIndex = gun_index;
  18724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18725. {
  18726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18727. {
  18728. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18729. }
  18730. }
  18731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18732. }
  18733. else
  18734. {
  18735. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18736. {
  18737. tempIndex = 2;
  18738. }
  18739. else
  18740. {
  18741. tempIndex = gun_index;
  18742. }
  18743. for (int index = 0; index < AC_QUANTITY; index++)
  18744. {
  18745. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18746. {
  18747. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18748. }
  18749. } // END for AC_QUANTITY
  18750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18751. }
  18752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18755. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18758. }
  18759. //2.4====================================== Voltage L1 ====================================================
  18760. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18761. {
  18762. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18764. {
  18765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18766. {
  18767. tempIndex = ((gun_index==2) ? 1: 0);
  18768. }
  18769. else
  18770. {
  18771. tempIndex = gun_index;
  18772. }
  18773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18774. {
  18775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18776. {
  18777. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18778. }
  18779. } // END OF FOR CHAdeMO_QUANTITY
  18780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18781. }
  18782. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18783. {
  18784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18785. {
  18786. tempIndex = ((gun_index==2) ? 1: 0);
  18787. }
  18788. else
  18789. {
  18790. tempIndex = gun_index;
  18791. }
  18792. for (int index = 0; index < CCS_QUANTITY; index++)
  18793. {
  18794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18795. {
  18796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18797. }
  18798. } // END OF FOR CCS_QUANTITY
  18799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18800. }
  18801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18802. {
  18803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18804. {
  18805. tempIndex = ((gun_index==2) ? 1: 0);
  18806. }
  18807. else
  18808. {
  18809. tempIndex = gun_index;
  18810. }
  18811. for (int index = 0; index < GB_QUANTITY; index++)
  18812. {
  18813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18814. {
  18815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18816. }
  18817. } // END OF FOR GB_QUANTITY
  18818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18819. }
  18820. else if(gunType[gun_index] == GUN_TYPE_DO)
  18821. {
  18822. tempIndex = gun_index;
  18823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18824. {
  18825. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18826. {
  18827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18828. }
  18829. }
  18830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18831. }
  18832. else
  18833. {
  18834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18835. {
  18836. tempIndex = 2;
  18837. }
  18838. else
  18839. {
  18840. tempIndex = gun_index;
  18841. }
  18842. for (int index = 0; index < AC_QUANTITY; index++)
  18843. {
  18844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18845. {
  18846. 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
  18847. }
  18848. } // END OF FOR AC_QUANTITY
  18849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18850. }
  18851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18854. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18857. }
  18858. //2.5============================================== End SoC =========================================================
  18859. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18860. {
  18861. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18862. 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))
  18863. {
  18864. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18865. {
  18866. tempIndex = ((gun_index==2) ? 1: 0);
  18867. }
  18868. else
  18869. {
  18870. tempIndex = gun_index;
  18871. }
  18872. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18873. {
  18874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18875. {
  18876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18877. {
  18878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18879. }
  18880. }
  18881. }
  18882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18883. {
  18884. for (int index = 0; index < CCS_QUANTITY; index++)
  18885. {
  18886. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18887. {
  18888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18889. }
  18890. }
  18891. }
  18892. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18893. {
  18894. for (int index = 0; index < GB_QUANTITY; index++)
  18895. {
  18896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18897. {
  18898. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18899. }
  18900. }
  18901. }
  18902. else if(gunType[gun_index] == GUN_TYPE_DO)
  18903. {
  18904. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18905. {
  18906. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18907. {
  18908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18909. }
  18910. }
  18911. }
  18912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18918. } // END FOR DC CASE
  18919. }
  18920. //2.6====================================== Current.Import L2 ==============================================
  18921. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18922. {
  18923. // AC 3 phase L2 current
  18924. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18925. {
  18926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18927. {
  18928. tempIndex = 2;
  18929. }
  18930. else
  18931. {
  18932. tempIndex = gun_index;
  18933. }
  18934. for (int index = 0; index < AC_QUANTITY; index++)
  18935. {
  18936. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18937. {
  18938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18939. }
  18940. }// End of for AC_QUANTITY
  18941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18942. }
  18943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18948. }
  18949. //2.7====================================== Current.Import L3 ==============================================
  18950. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18951. {
  18952. // AC 3 phase L3 current
  18953. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18954. {
  18955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18956. {
  18957. tempIndex = 2;
  18958. }
  18959. else
  18960. {
  18961. tempIndex = gun_index;
  18962. }
  18963. for (int index = 0; index < AC_QUANTITY; index++)
  18964. {
  18965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18966. {
  18967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18968. }
  18969. }// End of for AC_QUANTITY
  18970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18971. }
  18972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18977. }
  18978. //2.9====================================== Voltage L2 ====================================================
  18979. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18980. {
  18981. // AC 3 phase L2 volatge
  18982. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18983. {
  18984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18985. {
  18986. tempIndex = 2;
  18987. }
  18988. else
  18989. {
  18990. tempIndex = gun_index;
  18991. }
  18992. for (int index = 0; index < AC_QUANTITY; index++)
  18993. {
  18994. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18995. {
  18996. 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
  18997. }
  18998. } // END OF FOR AC_QUANTITY
  18999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19000. }
  19001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19006. }
  19007. //2.10====================================== Voltage L3 ====================================================
  19008. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19009. {
  19010. // AC 3 phase L3 volatge
  19011. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19012. {
  19013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19014. {
  19015. tempIndex = 2;
  19016. }
  19017. else
  19018. {
  19019. tempIndex = gun_index;
  19020. }
  19021. for (int index = 0; index < AC_QUANTITY; index++)
  19022. {
  19023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19024. {
  19025. 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
  19026. }
  19027. } // END OF FOR AC_QUANTITY
  19028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19029. }
  19030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19035. }
  19036. //====================== Start SoC ================================
  19037. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19038. {
  19039. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19040. 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))
  19041. {
  19042. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19043. {
  19044. tempIndex = ((gun_index==2) ? 1: 0);
  19045. }
  19046. else
  19047. {
  19048. tempIndex = gun_index;
  19049. }
  19050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19051. {
  19052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19053. {
  19054. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19055. {
  19056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19057. }
  19058. }
  19059. }
  19060. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19061. {
  19062. for (int index = 0; index < CCS_QUANTITY; index++)
  19063. {
  19064. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19065. {
  19066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19067. }
  19068. }
  19069. }
  19070. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19071. {
  19072. for (int index = 0; index < GB_QUANTITY; index++)
  19073. {
  19074. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19075. {
  19076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19077. }
  19078. }
  19079. }
  19080. else if(gunType[gun_index] == GUN_TYPE_DO)
  19081. {
  19082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19083. {
  19084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19085. {
  19086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19087. }
  19088. }
  19089. }
  19090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19096. } // END FOR DC CASE
  19097. }
  19098. //======================================== Message create ==============================================
  19099. json_object *StopTransaction = json_object_new_object();
  19100. json_object *transactionDatas = json_object_new_array();
  19101. json_object *sampledValues = json_object_new_array();
  19102. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19103. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19104. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19105. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19106. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19107. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19108. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19109. {
  19110. json_object *transactionData = json_object_new_object();
  19111. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19112. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19113. {
  19114. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19115. {
  19116. json_object *sampledValue = json_object_new_object();
  19117. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19118. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19119. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19120. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19121. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19122. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19123. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19124. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19125. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19126. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19127. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19128. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19129. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19130. json_object_array_add(sampledValues, sampledValue);
  19131. }
  19132. }
  19133. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19134. json_object_array_add(transactionDatas, transactionData);
  19135. }
  19136. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19137. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19138. ,MESSAGE_TYPE_CALL
  19139. ,guid
  19140. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19141. json_object_put(StopTransaction);
  19142. // Check File "TempStopTransaction" Exist
  19143. if((access(TempStopTransaction,F_OK))!=-1)
  19144. {
  19145. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19146. fclose(fopen(TempStopTransaction, "w"));
  19147. }
  19148. else
  19149. {
  19150. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19151. FILE *log = fopen(TempStopTransaction, "w+");
  19152. if(log == NULL)
  19153. {
  19154. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19155. return ;
  19156. }
  19157. else
  19158. {
  19159. fclose(log);
  19160. }
  19161. }
  19162. //Add TempStopTransaction | Update TempStopTransaction
  19163. // open file for writing
  19164. FILE *outfile;
  19165. outfile = fopen (TempStopTransaction, "a");
  19166. //DEBUG_INFO("data = %s\n", queuedata);
  19167. fputs(queuedata, outfile);
  19168. fputs("\n", outfile);
  19169. fclose (outfile);
  19170. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19171. OCPP_updatePeriodEnergy(gun_index);
  19172. }
  19173. void checkTempStopTransaction(int gun_index)
  19174. {
  19175. FILE *fptr1;
  19176. char ch;
  19177. char str[QUEUE_MESSAGE_LENGTH]={0};
  19178. char guid[37]={0};
  19179. char tempdata[65]={0};
  19180. char connectorStr[2]={0};
  19181. char TempStopTransaction[256];
  19182. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19183. fptr1 = fopen(TempStopTransaction, "r");
  19184. //TempStopTransaction格式: 槍號,StopTransaction封包
  19185. if (!fptr1)
  19186. {
  19187. //printf(" File not found or unable to open the input file!!\n");
  19188. return ;
  19189. }
  19190. ch=fgetc(fptr1);
  19191. //printf(" Now the content of the file %s is : \n",fname);
  19192. rewind(fptr1);
  19193. if(ch!=EOF)
  19194. {
  19195. // copy all contents to the temporary file except the specific line
  19196. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19197. {
  19198. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19199. if(str[0]=='\0')
  19200. {
  19201. break;
  19202. }
  19203. //TempStopTransaction格式: 槍號,StopTransaction封包
  19204. strncpy(connectorStr, str, 1);
  19205. if(atoi(connectorStr) != (gun_index+1))
  19206. {
  19207. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19208. fclose(fptr1);
  19209. return ;
  19210. }
  19211. //random_uuid(guid);
  19212. strncpy(guid, str+6, 36); //copy guid
  19213. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19214. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19215. {
  19216. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19217. }
  19218. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19219. OCPP_insert_transaction_msg(NO, str);
  19220. memset(str,0,ARRAY_SIZE(str));
  19221. }
  19222. }
  19223. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19224. fclose(fptr1);
  19225. remove(TempStopTransaction); // remove the original file
  19226. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19227. }
  19228. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19229. {
  19230. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19231. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19232. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19233. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19234. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19235. }
  19236. int GetWebSocketPingInterval(void)
  19237. {
  19238. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19239. }
  19240. int GetServerSign(void)
  19241. {
  19242. return server_sign;
  19243. }
  19244. uint8_t GetOcppSecurityProfile()
  19245. {
  19246. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19247. }
  19248. void GetOcppChargerBoxId(uint8_t *data)
  19249. {
  19250. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19251. }
  19252. void GetOcppSecurityPassword(uint8_t *data)
  19253. {
  19254. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19255. }
  19256. void SetOcppVersion(uint8_t *version)
  19257. {
  19258. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19259. DEBUG_INFO("ocpp version: %s\n", version);
  19260. if(strstr((char*)version, "ocpp1.6") != NULL)
  19261. {
  19262. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19263. }
  19264. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19265. {
  19266. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19267. system("pkill OcppBackend");
  19268. }
  19269. }
  19270. void SetServerSign(int value)
  19271. {
  19272. server_sign = value;
  19273. }
  19274. int GetBootNotificationInterval(void)
  19275. {
  19276. return BootNotificationInterval;
  19277. }
  19278. int GetInternetConn(void)
  19279. {
  19280. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19281. }
  19282. int GetBackendConnectionTimeout(void)
  19283. {
  19284. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19285. }
  19286. int isConnectorInitMode(int gun_index)
  19287. {
  19288. int tempIndex = 0;
  19289. int result = TRUE;
  19290. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19292. {
  19293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19294. {
  19295. tempIndex = ((gun_index==2) ? 1: 0);
  19296. }
  19297. else
  19298. {
  19299. tempIndex = gun_index;
  19300. }
  19301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19302. {
  19303. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19304. {
  19305. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19306. } //end of the same index
  19307. }//end of for CHAdeMO_QUANTITY
  19308. }
  19309. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19310. {
  19311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19312. {
  19313. tempIndex = ((gun_index==2) ? 1: 0);
  19314. }
  19315. else
  19316. {
  19317. tempIndex = gun_index;
  19318. }
  19319. for (int index = 0; index < CCS_QUANTITY; index++)
  19320. {
  19321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19322. {
  19323. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19324. } //end of the same index
  19325. } // end of for CCS_QUANTITY
  19326. }
  19327. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19328. {
  19329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19330. {
  19331. tempIndex = ((gun_index==2) ? 1: 0);
  19332. }
  19333. else
  19334. {
  19335. tempIndex = gun_index;
  19336. }
  19337. for (int index = 0; index < GB_QUANTITY; index++)
  19338. {
  19339. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19340. {
  19341. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19342. } //end of the same index
  19343. } // end of for GB_QUANTITY
  19344. }
  19345. else if(gunType[gun_index] == GUN_TYPE_DO)
  19346. {
  19347. tempIndex = gun_index;
  19348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19349. {
  19350. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19351. {
  19352. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19353. } //end of the same index
  19354. }
  19355. }
  19356. else
  19357. {
  19358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19359. {
  19360. tempIndex = 2;
  19361. }
  19362. else
  19363. {
  19364. tempIndex = gun_index;
  19365. }
  19366. for (int index = 0; index < AC_QUANTITY; index++)
  19367. {
  19368. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19369. {
  19370. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19371. }//end of the same index
  19372. }//end of for AC_QUANTITY
  19373. }
  19374. return result;
  19375. }
  19376. void refreshProcDogTimer()
  19377. {
  19378. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19379. }
  19380. void InitialSystemValue(void)
  19381. {
  19382. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19383. locallistVersion=0;
  19384. BootNotificationInterval = 0;
  19385. authorizeRetryTimes = 0;
  19386. GunStatusInterval = 10;
  19387. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19388. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19389. //Hear Beat
  19390. HeartBeatWithNOResponse = 0;
  19391. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19392. FirstHeartBeat = 0;
  19393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19394. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19395. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19396. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19397. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19398. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19399. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19400. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19401. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19402. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19403. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19404. //Status && ConnectorPlugIn Setting
  19405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19406. {
  19407. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19408. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19409. }
  19410. for (int index = 0; index < CCS_QUANTITY; index++)
  19411. {
  19412. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19413. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19414. }
  19415. for (int index = 0; index < GB_QUANTITY; index++)
  19416. {
  19417. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19418. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19419. }
  19420. for (int index = 0; index < AC_QUANTITY; index++)
  19421. {
  19422. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19423. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19424. }
  19425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19426. {
  19427. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19428. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19429. }
  19430. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19431. {
  19432. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19433. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19434. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19435. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19436. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19437. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19438. }
  19439. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19440. refreshStartTimer(&clientTime.Heartbeat);
  19441. sleep(1);
  19442. }
  19443. void LWS_Send(char *str)
  19444. {
  19445. //=====================================================
  19446. // Check InternetConn 0: disconnected, 1: connected
  19447. //====================================================
  19448. if(GetOcppConnStatus() == 0)
  19449. {
  19450. DEBUG_INFO("offline now !!!\n");
  19451. return;
  19452. }
  19453. // Only disable isWebsocketSendable operation initiated by charger
  19454. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19455. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19456. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19457. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19458. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19459. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19460. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19461. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19462. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19463. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19464. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19465. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19466. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19467. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19468. {
  19469. isWebsocketSendable = 0;
  19470. }
  19471. pthread_mutex_lock(&lock_send);
  19472. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19473. sprintf((char *)SendBuffer, "%s", str);
  19474. SendBufLen = strlen(str);
  19475. pthread_mutex_unlock(&lock_send);
  19476. lws_callback_on_writable(wsi_client);
  19477. //lws_service(context, 0);
  19478. //sleep(1);
  19479. }
  19480. void LWS_SendNow(char *str)
  19481. {
  19482. //=====================================================
  19483. // Check InternetConn 0: disconnected, 1: connected
  19484. //====================================================
  19485. if(GetOcppConnStatus() == 0)
  19486. {
  19487. DEBUG_INFO("offline now !!!\n");
  19488. return;
  19489. }
  19490. // Only disable isWebsocketSendable operation initiated by charger
  19491. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19492. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19493. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19494. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19495. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19496. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19497. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19498. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19499. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19500. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19501. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19502. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19503. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19504. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19505. {
  19506. isWebsocketSendable = 0;
  19507. }
  19508. pthread_mutex_lock(&lock_send);
  19509. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19510. sprintf((char *)SendBuffer, "%s", str);
  19511. SendBufLen = strlen(str);
  19512. pthread_mutex_unlock(&lock_send);
  19513. lws_callback_on_writable(wsi_client);
  19514. lws_service(context, 0);
  19515. //sleep(1);
  19516. }