MessageHandler.c 987 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584
  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. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // TTIA routine
  368. //=========================================
  369. int sendTTIAInfo(uint8_t gun_index)
  370. {
  371. static int sn = 0;
  372. int result = FAIL;
  373. struct hostent *server;
  374. int udp_socket_fd;
  375. struct sockaddr_in dest_addr = {0};
  376. uint8_t tx_buf[80] = {0};
  377. uint8_t logBuf[256]= {0};
  378. uint8_t tx_len, tempIndex, socStart, socEnd;
  379. uint16_t PresentChargedEnergy;
  380. struct tm tmStart, tmEnd;
  381. DEBUG_INFO("sendTTIAInfo...\n");
  382. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  383. {
  384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  385. {
  386. tempIndex = ((gun_index==2) ? 1: 0);
  387. }
  388. else
  389. {
  390. tempIndex = gun_index;
  391. }
  392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  393. {
  394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  395. {
  396. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  397. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  398. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  399. }
  400. }
  401. }
  402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  403. {
  404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  405. {
  406. tempIndex = ((gun_index==2) ? 1: 0);
  407. }
  408. else
  409. {
  410. tempIndex = gun_index;
  411. }
  412. for (int index = 0; index < CCS_QUANTITY; index++)
  413. {
  414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  415. {
  416. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  417. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  418. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  419. }
  420. }
  421. }
  422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  423. {
  424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  425. {
  426. tempIndex = ((gun_index==2) ? 1: 0);
  427. }
  428. else
  429. {
  430. tempIndex = gun_index;
  431. }
  432. for (int index = 0; index < GB_QUANTITY; index++)
  433. {
  434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  435. {
  436. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  437. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  438. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  439. }
  440. }
  441. }
  442. else if(gunType[gun_index] == GUN_TYPE_DO)
  443. {
  444. tempIndex = gun_index;
  445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  446. {
  447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  448. {
  449. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  450. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  451. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  452. }
  453. }
  454. }
  455. else
  456. {
  457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  458. {
  459. tempIndex = 2;
  460. }
  461. else
  462. {
  463. tempIndex = gun_index;
  464. }
  465. for (int index = 0; index < AC_QUANTITY; index++)
  466. {
  467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  468. {
  469. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  470. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  471. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  472. }
  473. }// END
  474. }
  475. // Message assembly
  476. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  477. tx_buf[4] = 0x02; // Protocol Version
  478. tx_buf[5] = 0xb0; // Message ID
  479. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  480. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  481. tx_buf[8] = 0x00; // CarID low byte
  482. tx_buf[9] = 0x00; // CarID high byte
  483. tx_buf[10] = 0x00; // ID Storage
  484. tx_buf[11] = 0x00; // Driver lowest byte
  485. tx_buf[12] = 0x00; // Driver 2nd byte
  486. tx_buf[13] = 0x00; // Driver 3rd byte
  487. tx_buf[14] = 0x00; // Driver highest byte
  488. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  489. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  490. tx_buf[17] = 0x00; // Reserve
  491. tx_buf[18] = 60 & 0xff; // Payload length low byte
  492. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  493. // EVSE provider
  494. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  495. // EVSE provider
  496. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  497. // EVSE id
  498. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  499. // Connector id
  500. tx_buf[37] = gun_index;
  501. // EVSE station
  502. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  503. // Vehicle SN
  504. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  505. // Mileage
  506. tx_buf[61] = 0x00; // lowest byte
  507. tx_buf[62] = 0x00; // 2nd byte
  508. tx_buf[63] = 0x00; // highest byte
  509. // Start date time 6 bytes
  510. 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))
  511. {
  512. struct tm *tmTarget;
  513. struct timeb tbTarget;
  514. tmStart.tm_year -= 1900;
  515. tmStart.tm_mon -= 1;
  516. tmStart.tm_gmtoff = 0;
  517. tbTarget.time = mktime(&tmStart);
  518. tbTarget.timezone = 0;
  519. tbTarget.time += (8*3600);
  520. tmTarget = gmtime(&tbTarget.time);
  521. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  522. tx_buf[65] = (tmTarget->tm_mon+1);
  523. tx_buf[66] = tmTarget->tm_mday;
  524. tx_buf[67] = tmTarget->tm_hour;
  525. tx_buf[68] = tmTarget->tm_min;
  526. tx_buf[69] = tmTarget->tm_sec;
  527. }
  528. // Stop date time 6 bytes
  529. 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))
  530. {
  531. struct tm *tmTarget;
  532. struct timeb tbTarget;
  533. tmEnd.tm_year -= 1900;
  534. tmEnd.tm_mon -= 1;
  535. tmEnd.tm_gmtoff = 0;
  536. tbTarget.time = mktime(&tmEnd);
  537. tbTarget.timezone = 0;
  538. tbTarget.time += (8*3600);
  539. tmTarget = gmtime(&tbTarget.time);
  540. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  541. tx_buf[71] = (tmTarget->tm_mon+1);
  542. tx_buf[72] = tmTarget->tm_mday;
  543. tx_buf[73] = tmTarget->tm_hour;
  544. tx_buf[74] = tmTarget->tm_min;
  545. tx_buf[75] = tmTarget->tm_sec;
  546. }
  547. // Session energy 2 bytes
  548. tx_buf[76] = PresentChargedEnergy & 0xff;
  549. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  550. // Start SOC 1 byte
  551. tx_buf[78] = socStart;
  552. // Stop SOC 1 byte
  553. tx_buf[79] = socEnd;
  554. // Open socket
  555. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  556. if(udp_socket_fd == -1)
  557. {
  558. DEBUG_ERROR("UDP socket create failed!\n");
  559. }
  560. else
  561. {
  562. // Get server DNS entry
  563. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  564. if (server == NULL)
  565. {
  566. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  567. }
  568. else
  569. {
  570. // Build the server's Internet address
  571. bzero((char *) &dest_addr, sizeof(dest_addr));
  572. dest_addr.sin_family = AF_INET;
  573. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  574. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  576. {
  577. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  578. {
  579. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  580. }
  581. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  582. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  583. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  584. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  585. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  586. DEBUG_TTIA_INFO("---------- Header ----------\n");
  587. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  588. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  589. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  590. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  591. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  592. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  593. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  594. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  595. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  596. DEBUG_TTIA_INFO("Len: 0x3C\n");
  597. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  598. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  599. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  600. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  601. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  602. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  603. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  604. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  605. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  606. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  607. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  608. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  609. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  610. DEBUG_TTIA_INFO("=========================================\n");
  611. sn++;
  612. result = PASS;
  613. }
  614. else
  615. {
  616. DEBUG_ERROR("UDP sent out fail.\n");
  617. }
  618. }
  619. }
  620. return result;
  621. }
  622. //=========================================
  623. // Save configuration
  624. //=========================================
  625. int runShellCmd(const char*cmd)
  626. {
  627. int result = FAIL;
  628. char buf[256];
  629. FILE *fp;
  630. fp = popen(cmd, "r");
  631. if(fp != NULL)
  632. {
  633. while(fgets(buf, sizeof(buf), fp) != NULL)
  634. {
  635. DEBUG_INFO("%s\n", buf);
  636. }
  637. result = PASS;
  638. }
  639. pclose(fp);
  640. return result;
  641. }
  642. int StoreUsrConfigData(struct SysConfigData *UsrData)
  643. {
  644. int result = PASS;
  645. int fd,wrd;
  646. unsigned int i,Chk;
  647. unsigned char *ptr, *BufTmp;
  648. int MtdBlockSize = 0x300000;
  649. Chk=0;
  650. ptr=(unsigned char *)UsrData;
  651. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  652. {
  653. memset(BufTmp,0,MtdBlockSize);
  654. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  655. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  656. Chk+=*(BufTmp+i);
  657. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  658. // Output configuration to file.
  659. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  660. if (fd < 0)
  661. {
  662. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  663. free(BufTmp);
  664. return 0;
  665. }
  666. wrd=write(fd, BufTmp, MtdBlockSize);
  667. close(fd);
  668. if(wrd<MtdBlockSize)
  669. {
  670. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  671. free(BufTmp);
  672. return 0;
  673. }
  674. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  675. DEBUG_INFO("Erase /dev/mtd10.\n");
  676. runShellCmd("flash_erase /dev/mtd10 0 0");
  677. DEBUG_INFO("Write /dev/mtd10.\n");
  678. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  679. DEBUG_INFO("Erase /dev/mtd11.\n");
  680. runShellCmd("flash_erase /dev/mtd11 0 0");
  681. DEBUG_INFO("Write /dev/mtd11.\n");
  682. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  683. system("rm -f /mnt/EvseConfig.bin");
  684. DEBUG_INFO("EvseConfig write to flash OK\n");
  685. }
  686. else
  687. {
  688. DEBUG_ERROR("alloc BlockSize NG\r\n");
  689. result = FAIL;
  690. }
  691. if(BufTmp!=NULL)
  692. free(BufTmp);
  693. return result;
  694. }
  695. //=========================================
  696. // Sqlite3 related function
  697. //=========================================
  698. static int selectSqlCount = 0;
  699. static int callback(void *data, int argc, char **argv, char **azColName){
  700. int i;
  701. //printf("%s: ", (const char*)data);
  702. selectSqlCount = argc;
  703. for(i = 0; i<argc; i++){
  704. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  705. }
  706. //printf("\n");
  707. return 0;
  708. }
  709. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  710. //int i;
  711. //printf("%s:\n", (const char*)data);
  712. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  713. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  714. return 0;
  715. }
  716. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  717. //printf("%s:\n", (const char*)data);
  718. //idTag
  719. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  720. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  721. //parentIdTag
  722. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  723. //expir_date
  724. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  725. //status
  726. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  727. //version
  728. if(columenCount > 5)
  729. idTagQuery.listVersionInt = atoi(columnValue[5]);
  730. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  731. return 0;
  732. }
  733. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  734. {
  735. // localversion = argv[5] ? atoi(argv[5]) : 0;
  736. // printf("localversion=%d\n", localversion);
  737. return 0;
  738. }
  739. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  740. {
  741. for (int i = 0; i < n_columns; i++)
  742. {
  743. DEBUG_INFO("%s\t", col_values[i]);
  744. }
  745. DEBUG_INFO("\n");
  746. return 0;
  747. }
  748. int OCPP_cleanLocalCache()
  749. {
  750. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  751. char *errMsg = 0;
  752. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  753. if (SQLITE_OK != rc)
  754. {
  755. DEBUG_INFO("SQL error: %s\n",errMsg);
  756. return FALSE;
  757. }
  758. return TRUE;
  759. }
  760. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  761. {
  762. int isSuccess = TRUE;
  763. int ret = 0;
  764. //const char* data = "Callback function called";
  765. char sql[300];
  766. char zErrMsg[200];
  767. memset(sql, 0, 300);
  768. memset(zErrMsg, 0, 200);
  769. 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);
  770. //* Execute SQL statement */
  771. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  772. if( ret != SQLITE_OK )
  773. {
  774. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  775. isSuccess = FALSE;
  776. }
  777. return isSuccess;
  778. }
  779. void OCPP_getIdTagFromLocalCache(char idTag[])
  780. {
  781. int rc = 0;
  782. char sql[100];
  783. char zErrMsg[100];
  784. memset(sql, 0, 100);
  785. memset(zErrMsg, 0, 100);
  786. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  787. memset(&idTagQuery, 0, sizeof(idTagQuery));
  788. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  789. /* Execute SQL statement */
  790. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  791. if( rc != SQLITE_OK )
  792. {
  793. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  794. }
  795. }
  796. void OCPP_getListVerion()
  797. {
  798. int rc = 0;
  799. // const char* data = "Callback function called";
  800. char sql[100];
  801. char zErrMsg[100];
  802. memset(sql, 0, 100);
  803. memset(zErrMsg, 0, 100);
  804. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  805. /* Execute SQL statement */
  806. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  807. if( rc != SQLITE_OK )
  808. {
  809. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  810. }
  811. }
  812. void OCPP_get_TableAuthlocalAllData(void)
  813. {
  814. int rc = 0;
  815. char sql[100];
  816. char zErrMsg[100];
  817. memset(sql, 0, 100);
  818. memset(zErrMsg, 0, 100);
  819. sprintf(sql,"select * from ocpp_auth_local ");
  820. /* Execute SQL statement */
  821. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  822. if( rc != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. }
  826. //return ver;
  827. }
  828. int OCPP_cleanLocalList()
  829. {
  830. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  831. char *errMsg = 0;
  832. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  833. if (SQLITE_OK != rc)
  834. {
  835. DEBUG_INFO("%s\n",errMsg);
  836. return FALSE;
  837. }
  838. return TRUE;
  839. }
  840. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  841. {
  842. int isSuccess = FALSE;
  843. int ret = 0;
  844. //const char* data = "Callback function called";
  845. char sql[300];
  846. char zErrMsg[200];
  847. memset(sql, 0, 300);
  848. memset(zErrMsg, 0, 200);
  849. 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);
  850. //* Execute SQL statement */
  851. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  852. if( ret != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. return isSuccess;
  856. }
  857. memset(sql, 0, 300);
  858. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  859. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  860. if( ret != SQLITE_OK )
  861. {
  862. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  863. return isSuccess;
  864. }
  865. isSuccess = TRUE;
  866. return isSuccess;
  867. }
  868. void OCPP_getIdTagFromLocalList(char idTag[])
  869. {
  870. int rc = 0;
  871. // const char* data = "Callback function called";
  872. char sql[100];
  873. char zErrMsg[100];
  874. memset(sql, 0, 100);
  875. memset(zErrMsg, 0, 100);
  876. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  877. memset(&idTagQuery, 0, sizeof(idTagQuery));
  878. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  879. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  880. /* Execute SQL statement */
  881. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  882. if( rc != SQLITE_OK )
  883. {
  884. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  885. }
  886. //return ver;
  887. }
  888. void OCPP_deleteIdTagFromLocalList(char idTag[])
  889. {
  890. //int ver = 0;
  891. //int isSuccess = FALSE;
  892. int rc = 0;
  893. char sql[100];
  894. char zErrMsg[100];
  895. memset(sql, 0, 100);
  896. memset(zErrMsg, 0, 100);
  897. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  898. //* Execute SQL statement */
  899. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  900. if( rc != SQLITE_OK )
  901. {
  902. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  903. }
  904. }
  905. int getCurrentYear()
  906. {
  907. int result = 0;
  908. time_t CurrentTime;
  909. struct tm *tm;
  910. CurrentTime = time(NULL);
  911. tm=localtime(&CurrentTime);
  912. result = (tm->tm_year + 1900);
  913. return result;
  914. }
  915. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  916. {
  917. int result = PASS;
  918. char* errMsg = NULL;
  919. char sqlStr[8192];
  920. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  921. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  922. {
  923. result = FAIL;
  924. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  925. }
  926. 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));
  927. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  928. {
  929. result = FAIL;
  930. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  931. }
  932. return result;
  933. }
  934. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  935. {
  936. int isSuccess = TRUE;
  937. int tempIndex;
  938. json_object *EnergyDataTransfer = json_object_new_object();
  939. json_object *periodEnergys = json_object_new_object();
  940. char sql[1024];
  941. char zErrMsg[200];
  942. memset(sql, 0, ARRAY_SIZE(sql));
  943. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  945. {
  946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  947. {
  948. tempIndex = ((gun_index==2) ? 1: 0);
  949. }
  950. else
  951. {
  952. tempIndex = gun_index;
  953. }
  954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  955. {
  956. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  957. {
  958. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  959. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  960. {
  961. uint8_t period[3];
  962. sprintf((char*)period, "%d", idxPeriod);
  963. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  964. }
  965. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  966. } //end of the same index
  967. }//end of for CHAdeMO_QUANTITY
  968. }
  969. else if(gunType[gun_index] == GUN_TYPE_CCS)
  970. {
  971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  972. {
  973. tempIndex = ((gun_index==2) ? 1: 0);
  974. }
  975. else
  976. {
  977. tempIndex = gun_index;
  978. }
  979. for (int index = 0; index < CCS_QUANTITY; index++)
  980. {
  981. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  982. {
  983. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  984. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  985. {
  986. uint8_t period[3];
  987. sprintf((char*)period, "%d", idxPeriod);
  988. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  989. }
  990. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  991. } //end of the same index
  992. } // end of for CCS_QUANTITY
  993. }
  994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  995. {
  996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  997. {
  998. tempIndex = ((gun_index==2) ? 1: 0);
  999. }
  1000. else
  1001. {
  1002. tempIndex = gun_index;
  1003. }
  1004. for (int index = 0; index < GB_QUANTITY; index++)
  1005. {
  1006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1007. {
  1008. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1009. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1010. {
  1011. uint8_t period[3];
  1012. sprintf((char*)period, "%d", idxPeriod);
  1013. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1014. }
  1015. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1016. } //end of the same index
  1017. } // end of for GB_QUANTITY
  1018. }
  1019. else if(gunType[gun_index] == GUN_TYPE_DO)
  1020. {
  1021. tempIndex = gun_index;
  1022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1023. {
  1024. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1025. {
  1026. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1027. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1028. {
  1029. uint8_t period[3];
  1030. sprintf((char*)period, "%d", idxPeriod);
  1031. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1032. }
  1033. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1034. } //end of the same index
  1035. }
  1036. }
  1037. else
  1038. {
  1039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1040. {
  1041. tempIndex = 2;
  1042. }
  1043. else
  1044. {
  1045. tempIndex = gun_index;
  1046. }
  1047. for (int index = 0; index < AC_QUANTITY; index++)
  1048. {
  1049. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1050. {
  1051. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1052. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1053. {
  1054. uint8_t period[3];
  1055. sprintf((char*)period, "%d", idxPeriod);
  1056. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1057. }
  1058. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1059. }//end of the same index
  1060. }//end of for AC_QUANTITY
  1061. }
  1062. 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));
  1063. json_object_put(EnergyDataTransfer);
  1064. //* Execute SQL statement */
  1065. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1066. {
  1067. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1068. isSuccess = FALSE;
  1069. }
  1070. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1071. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1072. {
  1073. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1074. isSuccess = FALSE;
  1075. }
  1076. return isSuccess;
  1077. }
  1078. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1079. {
  1080. int isSuccess = TRUE;
  1081. char sql[512];
  1082. char zErrMsg[200];
  1083. int rows, cols;
  1084. char **resultData;
  1085. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1086. /* Execute SQL statement */
  1087. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1088. {
  1089. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1090. isSuccess = FALSE;
  1091. }
  1092. else
  1093. {
  1094. if((rows > 0) && (atoi(resultData[4]) > 0))
  1095. {
  1096. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1097. }
  1098. else
  1099. {
  1100. DEBUG_WARN("There is not match transaction data.\n");
  1101. isSuccess = FALSE;
  1102. }
  1103. }
  1104. return isSuccess;
  1105. }
  1106. 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)
  1107. {
  1108. int result = PASS;
  1109. char* errMsg = NULL;
  1110. char sqlStr[8192];
  1111. 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');",
  1112. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1119. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1120. {
  1121. result = FAIL;
  1122. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1123. }
  1124. return result;
  1125. }
  1126. int OCPP_update_deduct_info(int txId, char *creditNo)
  1127. {
  1128. int result = PASS;
  1129. char* errMsg = NULL;
  1130. char sqlStr[8192];
  1131. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1132. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1133. {
  1134. result = FAIL;
  1135. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1136. }
  1137. return result;
  1138. }
  1139. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1140. {
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1143. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1144. atoi(columnValue[1]),
  1145. columnValue[2],
  1146. atoi(columnValue[3])==1?"true":"false",
  1147. atoi(columnValue[4])==1?"true":"false",
  1148. columnValue[5],
  1149. columnValue[9]);
  1150. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1151. return 0;
  1152. }
  1153. void OCPP_query_deduct_info()
  1154. {
  1155. int rc = 0;
  1156. char sql[100];
  1157. char zErrMsg[100];
  1158. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1159. /* Execute SQL statement */
  1160. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1161. if( rc != SQLITE_OK )
  1162. {
  1163. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1164. }
  1165. }
  1166. void reportReaderStatus(int gun_index)
  1167. {
  1168. struct timeval tmnow;
  1169. struct tm *tm;
  1170. char buf[28];//, usec_buf[6];
  1171. gettimeofday(&tmnow, NULL);
  1172. time_t t;
  1173. t = time(NULL);
  1174. /*UTC time and date*/
  1175. tm = gmtime(&t);
  1176. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1177. #if 0 // remove temporally
  1178. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1179. strcat(buf,".");
  1180. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1181. strcat(buf,usec_buf);
  1182. #endif
  1183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1185. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1186. (gun_index+1),
  1187. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1188. buf,
  1189. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1190. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1191. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1192. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1193. }
  1194. //==========================================
  1195. // Check time passed since today
  1196. //==========================================
  1197. long long DiffTimebWithNow(struct timeb ST)
  1198. {
  1199. //return milli-second
  1200. struct timeb ET;
  1201. long long StartTime,StopTime;
  1202. ftime(&ET);
  1203. StartTime=(long long)ST.time;
  1204. StopTime=(long long)ET.time;
  1205. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1206. }
  1207. int getTimePassSinceToday(uint8_t gun_index)
  1208. {
  1209. int result = -1;
  1210. static time_t lastTime[4];
  1211. time_t t;
  1212. struct tm *tmStartToday;
  1213. struct timeb tbStartToday;
  1214. t=time(NULL);
  1215. if(difftime(t, lastTime[gun_index])>0)
  1216. {
  1217. tmStartToday=localtime(&t);
  1218. tmStartToday->tm_hour = 0;
  1219. tmStartToday->tm_min = 0;
  1220. tmStartToday->tm_sec = 0;
  1221. tbStartToday.time = mktime(tmStartToday);
  1222. tbStartToday.millitm = 0;
  1223. result = DiffTimebWithNow(tbStartToday)/1000;
  1224. lastTime[gun_index] = t;
  1225. }
  1226. return result;
  1227. }
  1228. void getNowDatetime(uint8_t *data)
  1229. {
  1230. time_t t = time(NULL);
  1231. struct tm tm = *localtime(&t);
  1232. 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);
  1233. }
  1234. int syncDateTimeRTC(uint8_t *data)
  1235. {
  1236. struct ParsingResult
  1237. {
  1238. int result;
  1239. int scanedElement;
  1240. int year;
  1241. int month;
  1242. int mday;
  1243. int hour;
  1244. int min;
  1245. int sec;
  1246. int tz_hour;
  1247. int tz_min;
  1248. float minSec;
  1249. }result;
  1250. struct tm tmOrg;
  1251. struct tm *tmTarget;
  1252. struct timeb tbTarget;
  1253. char buf[128];
  1254. memset(&result, 0x00, sizeof(struct ParsingResult));
  1255. result.result = PASS;
  1256. if(strstr((char*)data, ".") != NULL)
  1257. {
  1258. // Original data with mini second
  1259. if(strstr((char*)data, "Z") != NULL)
  1260. {
  1261. // Original data with Z
  1262. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1263. &result.year,
  1264. &result.month,
  1265. &result.mday,
  1266. &result.hour,
  1267. &result.min,
  1268. &result.sec,
  1269. &result.minSec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1275. &result.year,
  1276. &result.month,
  1277. &result.mday,
  1278. &result.hour,
  1279. &result.min,
  1280. &result.sec,
  1281. &result.minSec,
  1282. &result.tz_hour,
  1283. &result.tz_min);
  1284. }
  1285. }
  1286. else
  1287. {
  1288. // Original data without mini second
  1289. if(strstr((char*)data, "Z") != NULL)
  1290. {
  1291. // Original data with Z
  1292. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1293. &result.year,
  1294. &result.month,
  1295. &result.mday,
  1296. &result.hour,
  1297. &result.min,
  1298. &result.sec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1304. &result.year,
  1305. &result.month,
  1306. &result.mday,
  1307. &result.hour,
  1308. &result.min,
  1309. &result.sec,
  1310. &result.tz_hour,
  1311. &result.tz_min);
  1312. }
  1313. }
  1314. tmOrg.tm_year = result.year - 1900;
  1315. tmOrg.tm_mon = result.month - 1;
  1316. tmOrg.tm_mday = result.mday;
  1317. tmOrg.tm_hour = result.hour;
  1318. tmOrg.tm_min = result.min;
  1319. tmOrg.tm_sec = result.sec;
  1320. tmOrg.tm_gmtoff = 0;
  1321. tbTarget.time = mktime(&tmOrg);
  1322. tbTarget.timezone = 0;
  1323. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1324. tmTarget = gmtime(&tbTarget.time);
  1325. 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);
  1326. //DEBUG_INFO(" org date time: %s\n", data);
  1327. //DEBUG_INFO("parse date time: %s\n", buf);
  1328. system(buf);
  1329. system("/sbin/hwclock -w --systohc");
  1330. if(result.scanedElement < 6)
  1331. result.result = FAIL;
  1332. return result.result;
  1333. }
  1334. //==========================================
  1335. // GetCompositeSchedule logic related function
  1336. //==========================================
  1337. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1338. {
  1339. //return milli-second
  1340. unsigned int StartTime,StopTime;
  1341. StartTime=(unsigned int)ST.time;
  1342. StopTime=(unsigned int)ET.time;
  1343. return (StopTime-StartTime);
  1344. }
  1345. int DiffTimebWithNowSec(struct timeb ST)
  1346. {
  1347. //return milli-second
  1348. struct timeb ET;
  1349. unsigned int StartTime,StopTime;
  1350. ftime(&ET);
  1351. StartTime=(unsigned int)ST.time;
  1352. StopTime=(unsigned int)ET.time;
  1353. return (StopTime-StartTime);
  1354. }
  1355. int getStartStop(uint8_t *start, uint8_t *stop)
  1356. {
  1357. struct ParsingResult
  1358. {
  1359. int result;
  1360. int scanedElement;
  1361. int year;
  1362. int month;
  1363. int mday;
  1364. int hour;
  1365. int min;
  1366. int sec;
  1367. int tz_hour;
  1368. int tz_min;
  1369. float minSec;
  1370. };
  1371. struct ParsingResult parseStart;
  1372. struct ParsingResult parseStop;
  1373. int result = -1;
  1374. struct tm tmStart;
  1375. struct timeb tbStart;
  1376. struct tm tmStop;
  1377. struct timeb tbStop;
  1378. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1379. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1380. // Scan start & stop date time
  1381. if(strstr((char*)start, ".") != NULL)
  1382. {
  1383. // Original data with mini second
  1384. if(strstr((char*)start, "Z") != NULL)
  1385. {
  1386. // Original data with Z
  1387. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1388. &parseStart.year,
  1389. &parseStart.month,
  1390. &parseStart.mday,
  1391. &parseStart.hour,
  1392. &parseStart.min,
  1393. &parseStart.sec,
  1394. &parseStart.minSec);
  1395. }
  1396. else
  1397. {
  1398. // Original data without Z
  1399. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1400. &parseStart.year,
  1401. &parseStart.month,
  1402. &parseStart.mday,
  1403. &parseStart.hour,
  1404. &parseStart.min,
  1405. &parseStart.sec,
  1406. &parseStart.minSec,
  1407. &parseStart.tz_hour,
  1408. &parseStart.tz_min);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. // Original data without mini second
  1414. if(strstr((char*)start, "Z") != NULL)
  1415. {
  1416. // Original data with Z
  1417. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1418. &parseStart.year,
  1419. &parseStart.month,
  1420. &parseStart.mday,
  1421. &parseStart.hour,
  1422. &parseStart.min,
  1423. &parseStart.sec);
  1424. }
  1425. else
  1426. {
  1427. // Original data without Z
  1428. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1429. &parseStart.year,
  1430. &parseStart.month,
  1431. &parseStart.mday,
  1432. &parseStart.hour,
  1433. &parseStart.min,
  1434. &parseStart.sec,
  1435. &parseStart.tz_hour,
  1436. &parseStart.tz_min);
  1437. }
  1438. }
  1439. if(strstr((char*)stop, ".") != NULL)
  1440. {
  1441. // Original data with mini second
  1442. if(strstr((char*)stop, "Z") != NULL)
  1443. {
  1444. // Original data with Z
  1445. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1446. &parseStop.year,
  1447. &parseStop.month,
  1448. &parseStop.mday,
  1449. &parseStop.hour,
  1450. &parseStop.min,
  1451. &parseStop.sec,
  1452. &parseStop.minSec);
  1453. }
  1454. else
  1455. {
  1456. // Original data without Z
  1457. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1458. &parseStop.year,
  1459. &parseStop.month,
  1460. &parseStop.mday,
  1461. &parseStop.hour,
  1462. &parseStop.min,
  1463. &parseStop.sec,
  1464. &parseStop.minSec,
  1465. &parseStop.tz_hour,
  1466. &parseStop.tz_min);
  1467. }
  1468. }
  1469. else
  1470. {
  1471. // Original data without mini second
  1472. if(strstr((char*)stop, "Z") != NULL)
  1473. {
  1474. // Original data with Z
  1475. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1476. &parseStop.year,
  1477. &parseStop.month,
  1478. &parseStop.mday,
  1479. &parseStop.hour,
  1480. &parseStop.min,
  1481. &parseStop.sec);
  1482. }
  1483. else
  1484. {
  1485. // Original data without Z
  1486. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1487. &parseStop.year,
  1488. &parseStop.month,
  1489. &parseStop.mday,
  1490. &parseStop.hour,
  1491. &parseStop.min,
  1492. &parseStop.sec,
  1493. &parseStop.tz_hour,
  1494. &parseStop.tz_min);
  1495. }
  1496. }
  1497. // Calculate date time difference
  1498. if((parseStart.scanedElement >=6) &&
  1499. (parseStop.scanedElement >=6))
  1500. {
  1501. //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);
  1502. //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);
  1503. tmStart.tm_year = parseStart.year - 1900;
  1504. tmStart.tm_mon = parseStart.month - 1;
  1505. tmStart.tm_mday = parseStart.mday;
  1506. tmStart.tm_hour = parseStart.hour;
  1507. tmStart.tm_min = parseStart.min;
  1508. tmStart.tm_sec = parseStart.sec;
  1509. tmStart.tm_gmtoff = 0;
  1510. tbStart.time = mktime(&tmStart);
  1511. tbStart.timezone = 0;
  1512. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1513. tmStop.tm_year = parseStop.year - 1900;
  1514. tmStop.tm_mon = parseStop.month - 1;
  1515. tmStop.tm_mday = parseStop.mday;
  1516. tmStop.tm_hour = parseStop.hour;
  1517. tmStop.tm_min = parseStop.min;
  1518. tmStop.tm_sec = parseStop.sec;
  1519. tmStop.tm_gmtoff = 0;
  1520. tbStop.time = mktime(&tmStop);
  1521. tbStop.timezone = 0;
  1522. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1523. result = DiffTimebSec(tbStart, tbStop);
  1524. //DEBUG_INFO("getStartStop(): %d\n", result);
  1525. }
  1526. else
  1527. {
  1528. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1529. }
  1530. return result;
  1531. }
  1532. int isOvertNow(uint8_t *start)
  1533. {
  1534. int result = NO;
  1535. struct ParsingResult
  1536. {
  1537. int result;
  1538. int scanedElement;
  1539. int year;
  1540. int month;
  1541. int mday;
  1542. int hour;
  1543. int min;
  1544. int sec;
  1545. int tz_hour;
  1546. int tz_min;
  1547. float minSec;
  1548. }parsingResult;
  1549. struct tm tmStart;
  1550. struct timeb tbStart;
  1551. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1552. if(strstr((char*)start, ".") != NULL)
  1553. {
  1554. // Original data with mini second
  1555. if(strstr((char*)start, "Z") != NULL)
  1556. {
  1557. // Original data with Z
  1558. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1559. &parsingResult.year,
  1560. &parsingResult.month,
  1561. &parsingResult.mday,
  1562. &parsingResult.hour,
  1563. &parsingResult.min,
  1564. &parsingResult.sec,
  1565. &parsingResult.minSec);
  1566. }
  1567. else
  1568. {
  1569. // Original data without Z
  1570. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1571. &parsingResult.year,
  1572. &parsingResult.month,
  1573. &parsingResult.mday,
  1574. &parsingResult.hour,
  1575. &parsingResult.min,
  1576. &parsingResult.sec,
  1577. &parsingResult.minSec,
  1578. &parsingResult.tz_hour,
  1579. &parsingResult.tz_min);
  1580. }
  1581. }
  1582. else
  1583. {
  1584. // Original data without mini second
  1585. if(strstr((char*)start, "Z") != NULL)
  1586. {
  1587. // Original data with Z
  1588. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1589. &parsingResult.year,
  1590. &parsingResult.month,
  1591. &parsingResult.mday,
  1592. &parsingResult.hour,
  1593. &parsingResult.min,
  1594. &parsingResult.sec);
  1595. }
  1596. else
  1597. {
  1598. // Original data without Z
  1599. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1600. &parsingResult.year,
  1601. &parsingResult.month,
  1602. &parsingResult.mday,
  1603. &parsingResult.hour,
  1604. &parsingResult.min,
  1605. &parsingResult.sec,
  1606. &parsingResult.tz_hour,
  1607. &parsingResult.tz_min);
  1608. }
  1609. }
  1610. if(parsingResult.scanedElement >= 6)
  1611. {
  1612. tmStart.tm_year = parsingResult.year - 1900;
  1613. tmStart.tm_mon = parsingResult.month - 1;
  1614. tmStart.tm_mday = parsingResult.mday;
  1615. tmStart.tm_hour = parsingResult.hour;
  1616. tmStart.tm_min = parsingResult.min;
  1617. tmStart.tm_sec = parsingResult.sec;
  1618. tmStart.tm_gmtoff = 0;
  1619. tbStart.time = mktime(&tmStart);
  1620. tbStart.timezone = 0;
  1621. tbStart.millitm = 0;
  1622. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1623. if(DiffTimebWithNowSec(tbStart) <= 0)
  1624. result = NO;
  1625. else
  1626. result = YES;
  1627. }
  1628. else
  1629. {
  1630. DEBUG_WARN("Start date parsing error.\n");
  1631. }
  1632. return result;
  1633. }
  1634. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1635. {
  1636. struct ParsingResult
  1637. {
  1638. int result;
  1639. int scanedElement;
  1640. int year;
  1641. int month;
  1642. int mday;
  1643. int hour;
  1644. int min;
  1645. int sec;
  1646. int tz_hour;
  1647. int tz_min;
  1648. float minSec;
  1649. };
  1650. struct ParsingResult parseStart;
  1651. struct ParsingResult parseStop;
  1652. int result = -1;
  1653. struct tm tmStart;
  1654. struct timeb tbStart;
  1655. struct tm tmStop;
  1656. struct timeb tbStop;
  1657. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1658. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1659. // Scan start & stop date time
  1660. if(strstr((char*)start, ".") != NULL)
  1661. {
  1662. // Original data with mini second
  1663. if(strstr((char*)start, "Z") != NULL)
  1664. {
  1665. // Original data with Z
  1666. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1667. &parseStart.year,
  1668. &parseStart.month,
  1669. &parseStart.mday,
  1670. &parseStart.hour,
  1671. &parseStart.min,
  1672. &parseStart.sec,
  1673. &parseStart.minSec);
  1674. }
  1675. else
  1676. {
  1677. // Original data without Z
  1678. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1679. &parseStart.year,
  1680. &parseStart.month,
  1681. &parseStart.mday,
  1682. &parseStart.hour,
  1683. &parseStart.min,
  1684. &parseStart.sec,
  1685. &parseStart.minSec,
  1686. &parseStart.tz_hour,
  1687. &parseStart.tz_min);
  1688. }
  1689. }
  1690. else
  1691. {
  1692. // Original data without mini second
  1693. if(strstr((char*)start, "Z") != NULL)
  1694. {
  1695. // Original data with Z
  1696. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1697. &parseStart.year,
  1698. &parseStart.month,
  1699. &parseStart.mday,
  1700. &parseStart.hour,
  1701. &parseStart.min,
  1702. &parseStart.sec);
  1703. }
  1704. else
  1705. {
  1706. // Original data without Z
  1707. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1708. &parseStart.year,
  1709. &parseStart.month,
  1710. &parseStart.mday,
  1711. &parseStart.hour,
  1712. &parseStart.min,
  1713. &parseStart.sec,
  1714. &parseStart.tz_hour,
  1715. &parseStart.tz_min);
  1716. }
  1717. }
  1718. if(strstr((char*)stop, ".") != NULL)
  1719. {
  1720. // Original data with mini second
  1721. if(strstr((char*)stop, "Z") != NULL)
  1722. {
  1723. // Original data with Z
  1724. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1725. &parseStop.year,
  1726. &parseStop.month,
  1727. &parseStop.mday,
  1728. &parseStop.hour,
  1729. &parseStop.min,
  1730. &parseStop.sec,
  1731. &parseStop.minSec);
  1732. }
  1733. else
  1734. {
  1735. // Original data without Z
  1736. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1737. &parseStop.year,
  1738. &parseStop.month,
  1739. &parseStop.mday,
  1740. &parseStop.hour,
  1741. &parseStop.min,
  1742. &parseStop.sec,
  1743. &parseStop.minSec,
  1744. &parseStop.tz_hour,
  1745. &parseStop.tz_min);
  1746. }
  1747. }
  1748. else
  1749. {
  1750. // Original data without mini second
  1751. if(strstr((char*)stop, "Z") != NULL)
  1752. {
  1753. // Original data with Z
  1754. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1755. &parseStop.year,
  1756. &parseStop.month,
  1757. &parseStop.mday,
  1758. &parseStop.hour,
  1759. &parseStop.min,
  1760. &parseStop.sec);
  1761. }
  1762. else
  1763. {
  1764. // Original data without Z
  1765. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1766. &parseStop.year,
  1767. &parseStop.month,
  1768. &parseStop.mday,
  1769. &parseStop.hour,
  1770. &parseStop.min,
  1771. &parseStop.sec,
  1772. &parseStop.tz_hour,
  1773. &parseStop.tz_min);
  1774. }
  1775. }
  1776. // Calculate date time difference
  1777. if((parseStart.scanedElement >=6) &&
  1778. (parseStop.scanedElement >=6))
  1779. {
  1780. //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);
  1781. //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);
  1782. tmStart.tm_year = parseStart.year - 1900;
  1783. tmStart.tm_mon = parseStart.month - 1;
  1784. tmStart.tm_mday = parseStart.mday;
  1785. tmStart.tm_hour = parseStart.hour;
  1786. tmStart.tm_min = parseStart.min;
  1787. tmStart.tm_sec = parseStart.sec;
  1788. tmStart.tm_gmtoff = 0;
  1789. tbStart.time = mktime(&tmStart);
  1790. tbStart.timezone = 0;
  1791. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1792. tmStop.tm_year = parseStop.year - 1900;
  1793. tmStop.tm_mon = parseStop.month - 1;
  1794. tmStop.tm_mday = parseStop.mday;
  1795. tmStop.tm_hour = parseStop.hour;
  1796. tmStop.tm_min = parseStop.min;
  1797. tmStop.tm_sec = parseStop.sec;
  1798. tmStop.tm_gmtoff = 0;
  1799. tbStop.time = mktime(&tmStop);
  1800. tbStop.timezone = 0;
  1801. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1802. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1803. //DEBUG_INFO("getStartStop(): %d\n", result);
  1804. }
  1805. else
  1806. {
  1807. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1808. }
  1809. return result;
  1810. }
  1811. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1812. {
  1813. FILE *fp;
  1814. char profileFileName[128];
  1815. char *line = NULL;
  1816. size_t len = 0;
  1817. time_t CurrentTime;
  1818. struct tm *tmComposite;
  1819. struct StructChargingProfile maxProfile;
  1820. struct StructChargingProfile compositeProfile;
  1821. uint8_t limitMax=0;
  1822. int compositePeriodIdx = 0;
  1823. //uint8_t isDurationNull = FALSE;
  1824. CurrentTime = time(NULL);
  1825. tmComposite=localtime(&CurrentTime);
  1826. 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);
  1827. if(isUnitA)
  1828. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1829. else
  1830. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1831. compositeProfile.ChargingSchedule.Duration = durationReq;
  1832. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1833. {
  1834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1835. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1836. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1837. }
  1838. compositeProfile.ChargingProfileId = 0;
  1839. compositeProfile.StackLevel = 99 ;
  1840. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1841. maxProfile.ChargingProfileId = -1;
  1842. maxProfile.ChargingSchedule.Duration = -1;
  1843. system("rm -f /tmp/*.json");
  1844. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1845. // Search max profile
  1846. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1847. if((access(profileFileName, F_OK))!=-1)
  1848. {
  1849. fp = fopen(profileFileName, "r");
  1850. while(getline(&line, &len, fp) != -1)
  1851. {
  1852. json_object *obj = NULL;
  1853. obj = json_tokener_parse(line);
  1854. if(is_error(obj))
  1855. {
  1856. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1857. }
  1858. else
  1859. {
  1860. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1861. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1862. )
  1863. {
  1864. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1865. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1866. )
  1867. {
  1868. struct tm tmFrom, tmTo;
  1869. struct timeb tbFrom, tbTo;
  1870. 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) &&
  1871. (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))
  1872. {
  1873. tmFrom.tm_year -= 1900;
  1874. tmFrom.tm_mon -= 1;
  1875. tbFrom.time = mktime(&tmFrom);
  1876. tmTo.tm_year -= 1900;
  1877. tmTo.tm_mon -= 1;
  1878. tbTo.time = mktime(&tmTo);
  1879. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1880. {
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1886. }
  1887. if(maxProfile.ChargingProfileId == -1)
  1888. DEBUG_INFO("MaxProfile found.\n");
  1889. else
  1890. DEBUG_INFO("MaxProfile updated.\n");
  1891. // Required item
  1892. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1893. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1894. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1895. if(isUnitA)
  1896. {
  1897. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1898. 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++)
  1899. {
  1900. 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"));
  1901. 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?
  1902. 3:
  1903. 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")));
  1904. 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")));
  1905. }
  1906. }
  1907. else
  1908. {
  1909. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1910. 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++)
  1911. {
  1912. 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"));
  1913. 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?
  1914. 3:
  1915. 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")));
  1916. 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));
  1917. }
  1918. }
  1919. // Optional item
  1920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1921. {
  1922. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1923. }
  1924. else
  1925. {
  1926. sprintf((char*)maxProfile.ValidFrom, " ");
  1927. }
  1928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1929. {
  1930. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1931. }
  1932. else
  1933. {
  1934. sprintf((char*)maxProfile.ValidTo, " ");
  1935. }
  1936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1937. {
  1938. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1939. }
  1940. else
  1941. {
  1942. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1943. }
  1944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1945. {
  1946. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1947. }
  1948. else
  1949. {
  1950. maxProfile.TransactionId = -1;
  1951. }
  1952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1953. {
  1954. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1955. }
  1956. else
  1957. {
  1958. maxProfile.ChargingSchedule.Duration = 86400;
  1959. //isDurationNull = TRUE;
  1960. }
  1961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1962. {
  1963. 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")));
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1968. }
  1969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1970. {
  1971. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1972. }
  1973. else
  1974. {
  1975. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1976. }
  1977. }
  1978. }
  1979. }
  1980. else
  1981. {
  1982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1983. {
  1984. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1986. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1987. }
  1988. if(maxProfile.ChargingProfileId == -1)
  1989. DEBUG_INFO("MaxProfile found.\n");
  1990. else
  1991. DEBUG_INFO("MaxProfile updated.\n");
  1992. // Required item
  1993. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1994. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1995. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1996. if(isUnitA)
  1997. {
  1998. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1999. 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++)
  2000. {
  2001. 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"));
  2002. 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?
  2003. 3:
  2004. 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")));
  2005. 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")));
  2006. }
  2007. }
  2008. else
  2009. {
  2010. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2011. 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++)
  2012. {
  2013. 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"));
  2014. 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?
  2015. 3:
  2016. 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")));
  2017. 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));
  2018. }
  2019. }
  2020. // Optional item
  2021. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2022. {
  2023. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2024. }
  2025. else
  2026. {
  2027. sprintf((char*)maxProfile.ValidFrom, " ");
  2028. }
  2029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2030. {
  2031. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2032. }
  2033. else
  2034. {
  2035. sprintf((char*)maxProfile.ValidTo, " ");
  2036. }
  2037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2038. {
  2039. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2040. }
  2041. else
  2042. {
  2043. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2044. }
  2045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2046. {
  2047. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2048. }
  2049. else
  2050. {
  2051. maxProfile.TransactionId = -1;
  2052. }
  2053. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2054. {
  2055. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2056. }
  2057. else
  2058. {
  2059. maxProfile.ChargingSchedule.Duration = 86400;
  2060. //isDurationNull = TRUE;
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2063. {
  2064. 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")));
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2069. }
  2070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2071. {
  2072. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2073. }
  2074. else
  2075. {
  2076. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2077. }
  2078. }
  2079. }
  2080. }
  2081. json_object_put(obj);
  2082. }
  2083. fclose(fp);
  2084. /*
  2085. if(maxProfile.ChargingProfileId !=-1)
  2086. {
  2087. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2088. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2089. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2090. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2091. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2092. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2093. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2094. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2095. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2096. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2097. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2098. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2099. {
  2100. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2101. {
  2102. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2103. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2104. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2105. }
  2106. }
  2107. }
  2108. else
  2109. DEBUG_INFO("MaxProfile not found.\n");
  2110. DEBUG_INFO("------------------------------------\n");*/
  2111. }
  2112. if(maxProfile.ChargingProfileId != -1)
  2113. {
  2114. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2115. {
  2116. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2117. {
  2118. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. }
  2122. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2123. {
  2124. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2125. {
  2126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2127. 0:
  2128. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2129. if(idxPeriod > 0)
  2130. {
  2131. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2132. {
  2133. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2140. {
  2141. if(maxProfile.ChargingSchedule.Duration != -1)
  2142. {
  2143. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2144. }
  2145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2146. {
  2147. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2148. {
  2149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2150. if(idxPeriod > 0)
  2151. {
  2152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2153. {
  2154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2163. {
  2164. if(maxProfile.ChargingSchedule.Duration != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. }
  2170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2171. {
  2172. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2173. {
  2174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2175. 0:
  2176. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2177. if(idxPeriod > 0)
  2178. {
  2179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2180. {
  2181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. else
  2188. {
  2189. if(maxProfile.ChargingSchedule.Duration != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. }
  2195. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2196. {
  2197. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2198. {
  2199. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2200. 0:
  2201. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2202. if(idxPeriod > 0)
  2203. {
  2204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2205. {
  2206. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. /*
  2214. DEBUG_INFO("MaxProfile after align.\n");
  2215. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2216. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2217. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2218. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2219. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2220. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2221. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2222. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2223. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2224. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2225. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2226. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2227. {
  2228. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2229. {
  2230. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2231. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2232. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2233. }
  2234. }
  2235. DEBUG_INFO("------------------------------------\n");*/
  2236. }
  2237. // Find each profile period quantity
  2238. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2239. {
  2240. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2241. limitMax = idx+1;
  2242. }
  2243. if(maxProfile.ChargingProfileId != -1)
  2244. {
  2245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2246. {
  2247. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2249. (maxProfile.ChargingSchedule.Duration > 0))
  2250. {
  2251. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2252. {
  2253. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2254. compositePeriodIdx++;
  2255. }
  2256. else
  2257. {
  2258. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2259. }
  2260. }
  2261. }
  2262. }
  2263. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2264. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2265. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2266. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2268. {
  2269. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2270. {
  2271. compositeProfile.ChargingProfileId = 1;
  2272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2275. }
  2276. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2277. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2278. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2279. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2280. }
  2281. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2282. if(line)
  2283. free(line);
  2284. }
  2285. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2286. {
  2287. FILE *fp;
  2288. char profileFileName[128];
  2289. char *line = NULL;
  2290. size_t len = 0;
  2291. time_t CurrentTime;
  2292. struct tm *tmComposite;
  2293. struct StructChargingProfile maxProfile;
  2294. struct StructChargingProfile defaultTxProfile;
  2295. struct StructChargingProfile txProfile;
  2296. struct StructChargingProfile compositeProfile;
  2297. struct StructChargingSchedulePeriod tmpPeriod;
  2298. uint8_t limitMax=0;
  2299. uint8_t limitDef=0;
  2300. uint8_t limitTx=0;
  2301. int compositePeriodIdx = 0;
  2302. CurrentTime = time(NULL);
  2303. tmComposite=localtime(&CurrentTime);
  2304. 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);
  2305. if(isUnitA)
  2306. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2307. else
  2308. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2309. compositeProfile.ChargingSchedule.Duration = durationReq;
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2313. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2314. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2315. }
  2316. compositeProfile.ChargingProfileId = 0;
  2317. compositeProfile.StackLevel = 99 ;
  2318. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2319. maxProfile.ChargingProfileId = -1;
  2320. defaultTxProfile.ChargingProfileId = -1;
  2321. txProfile.ChargingProfileId = -1;
  2322. maxProfile.ChargingSchedule.Duration = -1;
  2323. defaultTxProfile.ChargingSchedule.Duration = -1;
  2324. txProfile.ChargingSchedule.Duration = -1;
  2325. system("rm -f /tmp/*.json");
  2326. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2327. /*
  2328. * Search valid charging profile
  2329. */
  2330. //DEBUG_INFO("====================================\n");
  2331. // Search tx profile
  2332. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2333. if((access(profileFileName, F_OK))!=-1)
  2334. {
  2335. fp = fopen(profileFileName, "r");
  2336. while(getline(&line, &len, fp) != -1)
  2337. {
  2338. json_object *obj = NULL;
  2339. obj = json_tokener_parse(line);
  2340. if(is_error(obj))
  2341. {
  2342. DEBUG_ERROR("Parse txProfile from file error.\n");
  2343. }
  2344. else
  2345. {
  2346. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2347. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2348. )
  2349. {
  2350. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2351. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. )
  2353. {
  2354. struct tm tmFrom, tmTo;
  2355. struct timeb tbFrom, tbTo;
  2356. 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) &&
  2357. (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))
  2358. {
  2359. tmFrom.tm_year -= 1900;
  2360. tmFrom.tm_mon -= 1;
  2361. tbFrom.time = mktime(&tmFrom);
  2362. tmTo.tm_year -= 1900;
  2363. tmTo.tm_mon -= 1;
  2364. tbTo.time = mktime(&tmTo);
  2365. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2366. {
  2367. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2368. {
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2370. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2371. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2372. }
  2373. if(txProfile.ChargingProfileId == -1)
  2374. DEBUG_INFO("TxProfile found.\n");
  2375. else
  2376. DEBUG_INFO("TxProfile updated.\n");
  2377. // Required item
  2378. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2379. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2380. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2381. if(isUnitA)
  2382. {
  2383. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2384. 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++)
  2385. {
  2386. 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"));
  2387. 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?
  2388. 3:
  2389. 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")));
  2390. 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")));
  2391. }
  2392. }
  2393. else
  2394. {
  2395. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2396. 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++)
  2397. {
  2398. 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"));
  2399. 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?
  2400. 3:
  2401. 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")));
  2402. 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));
  2403. }
  2404. }
  2405. // Optional item
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidFrom, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.ValidTo, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2423. {
  2424. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)txProfile.RecurrencyKind, " ");
  2429. }
  2430. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2431. {
  2432. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.TransactionId = -1;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2439. {
  2440. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2441. }
  2442. else
  2443. {
  2444. txProfile.ChargingSchedule.Duration = 86400;
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2447. {
  2448. 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")));
  2449. }
  2450. else
  2451. {
  2452. 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));
  2453. }
  2454. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2455. {
  2456. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2457. }
  2458. else
  2459. {
  2460. txProfile.ChargingSchedule.MinChargingRate = -1;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2468. {
  2469. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2470. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2471. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2472. }
  2473. if(txProfile.ChargingProfileId == -1)
  2474. DEBUG_INFO("TxProfile found.\n");
  2475. else
  2476. DEBUG_INFO("TxProfile updated.\n");
  2477. // Required item
  2478. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2479. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2480. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2481. if(isUnitA)
  2482. {
  2483. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2484. 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++)
  2485. {
  2486. 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"));
  2487. 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?
  2488. 3:
  2489. 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")));
  2490. 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")));
  2491. }
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2496. 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++)
  2497. {
  2498. 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"));
  2499. 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?
  2500. 3:
  2501. 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")));
  2502. 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));
  2503. }
  2504. }
  2505. // Optional item
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidFrom, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.ValidTo, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2523. {
  2524. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2525. }
  2526. else
  2527. {
  2528. sprintf((char*)txProfile.RecurrencyKind, " ");
  2529. }
  2530. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2531. {
  2532. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.TransactionId = -1;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2539. {
  2540. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2541. }
  2542. else
  2543. {
  2544. txProfile.ChargingSchedule.Duration = 86400;
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2547. {
  2548. 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")));
  2549. }
  2550. else
  2551. {
  2552. 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));
  2553. }
  2554. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2555. {
  2556. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2557. }
  2558. else
  2559. {
  2560. txProfile.ChargingSchedule.MinChargingRate = -1;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. json_object_put(obj);
  2566. }
  2567. fclose(fp);
  2568. /*
  2569. if(txProfile.ChargingProfileId != -1)
  2570. {
  2571. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2572. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2573. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2574. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2575. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2576. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2577. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2578. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2579. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2580. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2581. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2585. {
  2586. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2587. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2588. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2589. }
  2590. }
  2591. }
  2592. else
  2593. DEBUG_INFO("TxProfile not found.\n");*/
  2594. }
  2595. // Search default tx profile
  2596. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2597. if((access(profileFileName, F_OK))==-1)
  2598. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2599. if((access(profileFileName, F_OK))!=-1)
  2600. {
  2601. fp = fopen(profileFileName, "r");
  2602. while(getline(&line, &len, fp) != -1)
  2603. {
  2604. json_object *obj = NULL;
  2605. obj = json_tokener_parse(line);
  2606. if(is_error(obj))
  2607. {
  2608. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2609. }
  2610. else
  2611. {
  2612. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2613. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2614. )
  2615. {
  2616. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2617. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. )
  2619. {
  2620. struct tm tmFrom, tmTo;
  2621. struct timeb tbFrom, tbTo;
  2622. 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) &&
  2623. (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))
  2624. {
  2625. tmFrom.tm_year -= 1900;
  2626. tmFrom.tm_mon -= 1;
  2627. tbFrom.time = mktime(&tmFrom);
  2628. tmTo.tm_year -= 1900;
  2629. tmTo.tm_mon -= 1;
  2630. tbTo.time = mktime(&tmTo);
  2631. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2632. {
  2633. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2634. {
  2635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2636. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2637. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2638. }
  2639. if(defaultTxProfile.ChargingProfileId == -1)
  2640. DEBUG_INFO("TxDefaultProfile found.\n");
  2641. else
  2642. DEBUG_INFO("TxDefaultProfile updated.\n");
  2643. // Required item
  2644. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2645. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2646. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2647. if(isUnitA)
  2648. {
  2649. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2650. 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++)
  2651. {
  2652. 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"));
  2653. 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?
  2654. 3:
  2655. 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")));
  2656. 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")));
  2657. }
  2658. }
  2659. else
  2660. {
  2661. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2662. 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++)
  2663. {
  2664. 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"));
  2665. 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?
  2666. 3:
  2667. 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")));
  2668. 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));
  2669. }
  2670. }
  2671. // Optional item
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2689. {
  2690. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2691. }
  2692. else
  2693. {
  2694. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2695. }
  2696. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2697. {
  2698. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.TransactionId = -1;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2707. }
  2708. else
  2709. {
  2710. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2713. {
  2714. 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")));
  2715. }
  2716. else
  2717. {
  2718. 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));
  2719. }
  2720. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2723. }
  2724. else
  2725. {
  2726. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else
  2732. {
  2733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2734. {
  2735. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2736. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2737. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2738. }
  2739. if(defaultTxProfile.ChargingProfileId == -1)
  2740. DEBUG_INFO("TxDefaultProfile found.\n");
  2741. else
  2742. DEBUG_INFO("TxDefaultProfile updated.\n");
  2743. // Required item
  2744. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2745. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2746. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2747. if(isUnitA)
  2748. {
  2749. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2750. 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++)
  2751. {
  2752. 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"));
  2753. 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?
  2754. 3:
  2755. 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")));
  2756. 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")));
  2757. }
  2758. }
  2759. else
  2760. {
  2761. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2762. 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++)
  2763. {
  2764. 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"));
  2765. 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?
  2766. 3:
  2767. 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")));
  2768. 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));
  2769. }
  2770. }
  2771. // Optional item
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2789. {
  2790. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2791. }
  2792. else
  2793. {
  2794. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2795. }
  2796. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2797. {
  2798. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.TransactionId = -1;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2805. {
  2806. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2807. }
  2808. else
  2809. {
  2810. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2813. {
  2814. 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")));
  2815. }
  2816. else
  2817. {
  2818. 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));
  2819. }
  2820. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2821. {
  2822. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2823. }
  2824. else
  2825. {
  2826. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. json_object_put(obj);
  2832. }
  2833. fclose(fp);
  2834. /*
  2835. if(defaultTxProfile.ChargingProfileId != -1)
  2836. {
  2837. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2838. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2839. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2840. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2841. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2842. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2843. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2844. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2845. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2846. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2847. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2851. {
  2852. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2853. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2854. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2855. }
  2856. }
  2857. }
  2858. else
  2859. DEBUG_INFO("TxDefaultProfile not found.\n");
  2860. DEBUG_INFO("------------------------------------\n");*/
  2861. }
  2862. // Search max profile
  2863. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2864. if((access(profileFileName, F_OK))!=-1)
  2865. {
  2866. fp = fopen(profileFileName, "r");
  2867. while(getline(&line, &len, fp) != -1)
  2868. {
  2869. json_object *obj = NULL;
  2870. obj = json_tokener_parse(line);
  2871. if(is_error(obj))
  2872. {
  2873. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2874. }
  2875. else
  2876. {
  2877. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2878. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2879. )
  2880. {
  2881. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2882. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2883. )
  2884. {
  2885. struct tm tmFrom, tmTo;
  2886. struct timeb tbFrom, tbTo;
  2887. 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) &&
  2888. (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))
  2889. {
  2890. tmFrom.tm_year -= 1900;
  2891. tmFrom.tm_mon -= 1;
  2892. tbFrom.time = mktime(&tmFrom);
  2893. tmTo.tm_year -= 1900;
  2894. tmTo.tm_mon -= 1;
  2895. tbTo.time = mktime(&tmTo);
  2896. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2897. {
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2902. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2903. }
  2904. if(maxProfile.ChargingProfileId == -1)
  2905. DEBUG_INFO("MaxProfile found.\n");
  2906. else
  2907. DEBUG_INFO("MaxProfile updated.\n");
  2908. // Required item
  2909. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2910. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2911. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2912. if(isUnitA)
  2913. {
  2914. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2915. 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++)
  2916. {
  2917. 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"));
  2918. 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?
  2919. 3:
  2920. 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")));
  2921. 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")));
  2922. }
  2923. }
  2924. else
  2925. {
  2926. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2927. 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++)
  2928. {
  2929. 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"));
  2930. 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?
  2931. 3:
  2932. 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")));
  2933. 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));
  2934. }
  2935. }
  2936. // Optional item
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidFrom, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.ValidTo, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2954. {
  2955. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2956. }
  2957. else
  2958. {
  2959. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2960. }
  2961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2962. {
  2963. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.TransactionId = -1;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2970. {
  2971. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2972. }
  2973. else
  2974. {
  2975. maxProfile.ChargingSchedule.Duration = 86400;
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2978. {
  2979. 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")));
  2980. }
  2981. else
  2982. {
  2983. 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));
  2984. }
  2985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2986. {
  2987. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2988. }
  2989. else
  2990. {
  2991. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2992. }
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2999. {
  3000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3002. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3003. }
  3004. if(maxProfile.ChargingProfileId == -1)
  3005. DEBUG_INFO("MaxProfile found.\n");
  3006. else
  3007. DEBUG_INFO("MaxProfile updated.\n");
  3008. // Required item
  3009. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3010. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3011. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3012. if(isUnitA)
  3013. {
  3014. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3015. 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++)
  3016. {
  3017. 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"));
  3018. 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?
  3019. 3:
  3020. 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")));
  3021. 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")));
  3022. }
  3023. }
  3024. else
  3025. {
  3026. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3027. 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++)
  3028. {
  3029. 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"));
  3030. 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?
  3031. 3:
  3032. 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")));
  3033. 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));
  3034. }
  3035. }
  3036. // Optional item
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidFrom, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.ValidTo, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3054. {
  3055. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3056. }
  3057. else
  3058. {
  3059. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3060. }
  3061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3062. {
  3063. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.TransactionId = -1;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3070. {
  3071. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3072. }
  3073. else
  3074. {
  3075. maxProfile.ChargingSchedule.Duration = 86400;
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3078. {
  3079. 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")));
  3080. }
  3081. else
  3082. {
  3083. 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));
  3084. }
  3085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3086. {
  3087. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3088. }
  3089. else
  3090. {
  3091. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3092. }
  3093. }
  3094. }
  3095. }
  3096. json_object_put(obj);
  3097. }
  3098. fclose(fp);
  3099. /*
  3100. if(maxProfile.ChargingProfileId !=-1)
  3101. {
  3102. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3103. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3104. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3105. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3106. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3107. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3108. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3109. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3110. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3111. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3112. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3114. {
  3115. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3116. {
  3117. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3118. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3119. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3120. }
  3121. }
  3122. }
  3123. else
  3124. DEBUG_INFO("MaxProfile not found.\n");
  3125. DEBUG_INFO("------------------------------------\n");*/
  3126. }
  3127. /*
  3128. * Align found profile start schedule & periods
  3129. */
  3130. //DEBUG_INFO("====================================\n");
  3131. /*
  3132. // For local test usage, force modify found profile start schedule info
  3133. 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);
  3134. 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);
  3135. 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);
  3136. */
  3137. if(txProfile.ChargingProfileId != -1)
  3138. {
  3139. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3140. {
  3141. if(txProfile.ChargingSchedule.Duration != -1)
  3142. {
  3143. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. }
  3147. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3148. {
  3149. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3150. {
  3151. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3152. 0:
  3153. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3154. if(idxPeriod > 0)
  3155. {
  3156. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3157. {
  3158. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3159. }
  3160. }
  3161. }
  3162. }
  3163. }
  3164. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3165. {
  3166. if(txProfile.ChargingSchedule.Duration != -1)
  3167. {
  3168. 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?
  3169. 0:
  3170. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. }
  3172. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3173. {
  3174. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3175. {
  3176. 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?
  3177. 0:
  3178. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3179. if(idxPeriod > 0)
  3180. {
  3181. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3182. {
  3183. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3192. {
  3193. if(txProfile.ChargingSchedule.Duration != -1)
  3194. {
  3195. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. }
  3199. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3200. {
  3201. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3202. {
  3203. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3204. 0:
  3205. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3206. if(idxPeriod > 0)
  3207. {
  3208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3209. {
  3210. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3211. }
  3212. }
  3213. }
  3214. }
  3215. }
  3216. else
  3217. {
  3218. if(txProfile.ChargingSchedule.Duration != -1)
  3219. {
  3220. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. }
  3224. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3225. {
  3226. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3227. {
  3228. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3229. 0:
  3230. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3231. if(idxPeriod > 0)
  3232. {
  3233. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3234. {
  3235. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. /*
  3243. DEBUG_INFO("txProfile after align.\n");
  3244. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3245. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3246. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3247. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3248. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3250. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3251. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3252. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3253. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3254. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3256. {
  3257. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3258. {
  3259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3262. }
  3263. }*/
  3264. }
  3265. if(defaultTxProfile.ChargingProfileId != -1)
  3266. {
  3267. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. }
  3275. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3276. {
  3277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3278. {
  3279. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3280. 0:
  3281. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3282. if(idxPeriod > 0)
  3283. {
  3284. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3285. {
  3286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3295. {
  3296. 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?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. }
  3300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3303. {
  3304. 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?
  3305. 0:
  3306. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3307. if(idxPeriod > 0)
  3308. {
  3309. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3310. {
  3311. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. else
  3318. {
  3319. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. }
  3327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3328. {
  3329. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3330. {
  3331. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3332. 0:
  3333. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3334. if(idxPeriod > 0)
  3335. {
  3336. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3337. {
  3338. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3339. }
  3340. }
  3341. }
  3342. }
  3343. }
  3344. else
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. }
  3352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3353. {
  3354. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3355. {
  3356. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3357. 0:
  3358. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3359. if(idxPeriod > 0)
  3360. {
  3361. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3362. {
  3363. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. /*
  3371. DEBUG_INFO("defaultTxProfile after align.\n");
  3372. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3373. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3374. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3375. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3376. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3377. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3378. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3379. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3380. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3381. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3382. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3384. {
  3385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3386. {
  3387. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3388. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3389. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3390. }
  3391. }
  3392. DEBUG_INFO("------------------------------------\n");*/
  3393. }
  3394. if(maxProfile.ChargingProfileId != -1)
  3395. {
  3396. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3397. {
  3398. if(maxProfile.ChargingSchedule.Duration != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. }
  3404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3405. {
  3406. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3407. {
  3408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3409. 0:
  3410. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3411. if(idxPeriod > 0)
  3412. {
  3413. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3414. {
  3415. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3416. }
  3417. }
  3418. }
  3419. }
  3420. }
  3421. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3422. {
  3423. if(maxProfile.ChargingSchedule.Duration != -1)
  3424. {
  3425. 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?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. }
  3429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3430. {
  3431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3432. {
  3433. 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?
  3434. 0:
  3435. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3436. if(idxPeriod > 0)
  3437. {
  3438. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3439. {
  3440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. else
  3447. {
  3448. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3449. {
  3450. if(maxProfile.ChargingSchedule.Duration != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. }
  3456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3457. {
  3458. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3459. {
  3460. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3461. 0:
  3462. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3463. if(idxPeriod > 0)
  3464. {
  3465. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3466. {
  3467. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. else
  3474. {
  3475. if(maxProfile.ChargingSchedule.Duration != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. }
  3481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3482. {
  3483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3484. {
  3485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3486. 0:
  3487. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3488. if(idxPeriod > 0)
  3489. {
  3490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3491. {
  3492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. /*
  3500. DEBUG_INFO("MaxProfile after align.\n");
  3501. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3502. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3503. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3504. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3505. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3506. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3507. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3508. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3509. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3510. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3511. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3513. {
  3514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3515. {
  3516. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3517. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3518. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3519. }
  3520. }
  3521. DEBUG_INFO("------------------------------------\n");*/
  3522. }
  3523. /*
  3524. * Merge to conposite schedule
  3525. */
  3526. //DEBUG_INFO("====================================\n");
  3527. // Find each profile period quantity
  3528. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3529. {
  3530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3531. limitMax = idx+1;
  3532. }
  3533. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3534. {
  3535. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3536. limitDef = idx+1;
  3537. }
  3538. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3539. {
  3540. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3541. limitTx = idx+1;
  3542. }
  3543. // TxProfile found, composite schedule based on it
  3544. if(txProfile.ChargingProfileId != -1)
  3545. {
  3546. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3547. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3550. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3551. (txProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. if(maxProfile.ChargingProfileId != -1)
  3554. {
  3555. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3556. {
  3557. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3558. {
  3559. if((maxProfile.ChargingSchedule.Duration > 0))
  3560. {
  3561. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3562. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3563. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3564. }
  3565. else
  3566. {
  3567. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3568. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3569. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3570. }
  3571. }
  3572. if(idxMaxPeriod == (limitMax-1))
  3573. {
  3574. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3575. {
  3576. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3577. {
  3578. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3579. compositePeriodIdx++;
  3580. }
  3581. else
  3582. {
  3583. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3584. }
  3585. }
  3586. }
  3587. }
  3588. }
  3589. else
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3592. {
  3593. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3594. compositePeriodIdx++;
  3595. }
  3596. else
  3597. {
  3598. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3599. }
  3600. }
  3601. }
  3602. if(idxTxPeriod == (limitTx-1))
  3603. {
  3604. if(defaultTxProfile.ChargingProfileId != -1)
  3605. {
  3606. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3607. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3608. {
  3609. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3610. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3611. (defaultTxProfile.ChargingSchedule.Duration>0))
  3612. {
  3613. if(maxProfile.ChargingProfileId != -1)
  3614. {
  3615. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3616. {
  3617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3618. {
  3619. if((maxProfile.ChargingSchedule.Duration > 0))
  3620. {
  3621. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3622. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3623. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3624. }
  3625. else
  3626. {
  3627. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3628. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3629. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3630. }
  3631. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3632. {
  3633. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3634. {
  3635. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3636. compositePeriodIdx++;
  3637. }
  3638. else
  3639. {
  3640. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3641. }
  3642. }
  3643. // Delete duplicate period
  3644. if(compositePeriodIdx > 1)
  3645. {
  3646. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3647. {
  3648. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3649. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3650. compositePeriodIdx -= 1;
  3651. }
  3652. }
  3653. }
  3654. else
  3655. {
  3656. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3657. {
  3658. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3659. compositePeriodIdx++;
  3660. }
  3661. else
  3662. {
  3663. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3664. }
  3665. break;
  3666. }
  3667. }
  3668. }
  3669. else
  3670. {
  3671. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3672. {
  3673. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3674. compositePeriodIdx++;
  3675. }
  3676. else
  3677. {
  3678. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. }
  3687. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3688. else if(defaultTxProfile.ChargingProfileId != -1)
  3689. {
  3690. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3691. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3692. {
  3693. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3695. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3696. {
  3697. if(maxProfile.ChargingProfileId != -1)
  3698. {
  3699. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3700. {
  3701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3702. {
  3703. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3704. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3705. if((maxProfile.ChargingSchedule.Duration > 0))
  3706. {
  3707. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3708. }
  3709. else
  3710. {
  3711. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3712. }
  3713. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3714. {
  3715. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3716. {
  3717. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3718. compositePeriodIdx++;
  3719. }
  3720. else
  3721. {
  3722. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3723. }
  3724. }
  3725. // Delete duplicate period
  3726. if(compositePeriodIdx > 1)
  3727. {
  3728. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3729. {
  3730. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3731. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3732. compositePeriodIdx -= 1;
  3733. }
  3734. }
  3735. }
  3736. else
  3737. {
  3738. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3739. {
  3740. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3741. compositePeriodIdx++;
  3742. }
  3743. else
  3744. {
  3745. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3746. }
  3747. break;
  3748. }
  3749. }
  3750. }
  3751. else
  3752. {
  3753. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3754. {
  3755. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3756. compositePeriodIdx++;
  3757. }
  3758. else
  3759. {
  3760. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3761. }
  3762. }
  3763. }
  3764. }
  3765. }
  3766. // Fill other period by MaxProfile
  3767. if(maxProfile.ChargingProfileId != -1)
  3768. {
  3769. if(compositePeriodIdx==0)
  3770. {
  3771. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3772. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3773. {
  3774. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3775. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3776. (maxProfile.ChargingSchedule.Duration > 0))
  3777. {
  3778. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3779. {
  3780. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3781. compositePeriodIdx++;
  3782. }
  3783. else
  3784. {
  3785. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3786. }
  3787. }
  3788. }
  3789. }
  3790. else
  3791. {
  3792. int lastCompositePeriodIdx = compositePeriodIdx;
  3793. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3794. {
  3795. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3796. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3797. (maxProfile.ChargingSchedule.Duration > 0))
  3798. {
  3799. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3800. {
  3801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3802. {
  3803. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3804. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3805. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3806. }
  3807. else
  3808. {
  3809. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3810. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3811. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3812. }
  3813. }
  3814. if(tmpPeriod.Limit != -1)
  3815. {
  3816. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3817. {
  3818. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3819. {
  3820. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3821. compositePeriodIdx++;
  3822. }
  3823. else
  3824. {
  3825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3826. }
  3827. }
  3828. // Delete duplicate period
  3829. if(compositePeriodIdx > 1)
  3830. {
  3831. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3832. {
  3833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3835. compositePeriodIdx -= 1;
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. }
  3843. compositeProfile.ChargingSchedule.Duration = durationReq;
  3844. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3845. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3846. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3847. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3849. {
  3850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3851. {
  3852. compositeProfile.ChargingProfileId = 1;
  3853. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3854. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3855. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3856. }
  3857. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3858. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3859. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3861. }
  3862. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3863. if(line)
  3864. free(line);
  3865. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3866. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3867. }
  3868. //==========================================
  3869. // Init all share memory
  3870. //==========================================
  3871. int InitShareMemory()
  3872. {
  3873. int result = PASS;
  3874. int MeterSMId;
  3875. //creat ShmSysConfigAndInfo
  3876. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3877. {
  3878. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3879. result = FAIL;
  3880. }
  3881. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3882. {
  3883. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3884. result = FAIL;
  3885. }
  3886. else
  3887. {}
  3888. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3889. {
  3890. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3891. result = FAIL;
  3892. }
  3893. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3894. {
  3895. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else
  3899. {}
  3900. //creat ShmPsuData
  3901. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3902. {
  3903. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3904. result = FAIL;
  3905. }
  3906. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3907. {
  3908. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3909. result = FAIL;
  3910. }
  3911. else
  3912. {}
  3913. //creat ShmOCPP16Data
  3914. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3915. {
  3916. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3917. result = FAIL;
  3918. }
  3919. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3920. {
  3921. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3922. result = FAIL;
  3923. }
  3924. else
  3925. {}
  3926. /****************************** For Initial Settings************************************************/
  3927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3929. // allocate Configuration memory address
  3930. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3931. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3932. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3933. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3934. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3935. //offline MeterValue Interval
  3936. TempMeterValueInterval = 0;
  3937. return result;
  3938. }
  3939. int ProcessShareMemory()
  3940. {
  3941. int result = PASS;
  3942. if(InitShareMemory() == FAIL)
  3943. {
  3944. DEBUG_ERROR("InitShareMemory NG\n");
  3945. if(ShmStatusCodeData!=NULL)
  3946. {
  3947. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3948. }
  3949. result = FAIL;
  3950. }
  3951. // Model name parsing
  3952. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3953. {
  3954. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3955. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3956. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3957. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3958. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3959. ) // 'D' means DC
  3960. {
  3961. // DO series
  3962. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3963. {
  3964. gunTotalNumber += 1;
  3965. gunType[gun_index] = GUN_TYPE_DO;
  3966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3967. {
  3968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3969. {
  3970. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3971. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3972. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3973. }
  3974. }
  3975. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3976. {
  3977. case Gun_Type_Chademo:
  3978. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3979. break;
  3980. case Gun_Type_CCS_2:
  3981. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3982. break;
  3983. case Gun_Type_GB:
  3984. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3985. break;
  3986. case Gun_Type_AC:
  3987. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3988. break;
  3989. default:
  3990. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3991. break;
  3992. }
  3993. }
  3994. }
  3995. else
  3996. {
  3997. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3998. {
  3999. gunTotalNumber += 1;
  4000. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4001. {
  4002. case Gun_Type_Chademo:
  4003. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4004. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4005. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4008. {
  4009. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4010. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4011. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4012. }
  4013. }
  4014. break;
  4015. case Gun_Type_CCS_2:
  4016. gunType[gun_index] = GUN_TYPE_CCS;
  4017. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4018. for (int index = 0; index < CCS_QUANTITY; index++)
  4019. {
  4020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4021. {
  4022. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4023. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4024. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4025. }
  4026. }
  4027. break;
  4028. case Gun_Type_GB:
  4029. gunType[gun_index] = GUN_TYPE_GBT;
  4030. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4031. for (int index = 0; index < GB_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4034. {
  4035. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4036. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4037. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4038. }
  4039. }
  4040. break;
  4041. case Gun_Type_AC:
  4042. gunType[gun_index] = GUN_TYPE_AC;
  4043. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4044. for (int index = 0; index < AC_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4047. {
  4048. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4050. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4051. }
  4052. }
  4053. break;
  4054. default:
  4055. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4056. break;
  4057. }
  4058. }
  4059. }
  4060. }
  4061. else
  4062. {
  4063. DEBUG_ERROR("Model name parsing fail.\n");
  4064. result = FAIL;
  4065. }
  4066. if(result != PASS)sleep(5);
  4067. return result;
  4068. }
  4069. void checkRemoteStart(uint8_t connectorIdInt)
  4070. {
  4071. uint8_t tempIndex;
  4072. int result = PASS;
  4073. char cmdBuf[512];
  4074. //check Transaction active
  4075. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4076. {
  4077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4078. {
  4079. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4080. }
  4081. else
  4082. {
  4083. tempIndex = connectorIdInt -1;
  4084. }
  4085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4086. {
  4087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4088. {
  4089. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4091. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4092. {
  4093. //Reserved
  4094. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4095. }
  4096. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4097. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4098. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4099. {
  4100. //Reserved
  4101. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4102. result = FAIL;
  4103. goto end;
  4104. }
  4105. else
  4106. {
  4107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4108. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4109. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4110. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4111. {
  4112. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4113. result = FAIL;
  4114. goto end;
  4115. }
  4116. }//END FOR ELSE
  4117. }
  4118. }// END FOR CHAdeMO_QUANTITY
  4119. }
  4120. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4121. {
  4122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4123. {
  4124. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4125. }
  4126. else
  4127. {
  4128. tempIndex = connectorIdInt -1;
  4129. }
  4130. for (int index = 0; index < CCS_QUANTITY; index++)
  4131. {
  4132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4133. {
  4134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4135. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4136. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4137. {
  4138. //Reserved
  4139. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4140. }
  4141. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4142. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4143. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4144. {
  4145. //Reserved
  4146. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4147. result = FAIL;
  4148. goto end;
  4149. }
  4150. else
  4151. {
  4152. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4153. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4155. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4156. {
  4157. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4158. result = FAIL;
  4159. goto end;
  4160. }
  4161. }// END FOR ELSE
  4162. }
  4163. }// END FOR CCS_QUANTITY
  4164. }
  4165. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4170. }
  4171. else
  4172. {
  4173. tempIndex = connectorIdInt -1;
  4174. }
  4175. for (int index = 0; index < GB_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4178. {
  4179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4180. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4181. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4182. {
  4183. //Reserved
  4184. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4185. }
  4186. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4188. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4189. {
  4190. //Reserved
  4191. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4192. result = FAIL;
  4193. goto end;
  4194. }
  4195. else
  4196. {
  4197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4201. {
  4202. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4203. result = FAIL;
  4204. goto end;
  4205. }
  4206. }// END FOR ELSE
  4207. }
  4208. } // END FOR GB_QUANTITY
  4209. }
  4210. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4211. {
  4212. tempIndex = connectorIdInt -1;
  4213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4214. {
  4215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4216. {
  4217. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4218. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4219. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4220. {
  4221. //Reserved
  4222. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4223. }
  4224. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4225. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4226. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4227. {
  4228. //Reserved
  4229. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4230. result = FAIL;
  4231. goto end;
  4232. }
  4233. else
  4234. {
  4235. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4237. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4238. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4239. {
  4240. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4241. result = FAIL;
  4242. goto end;
  4243. }
  4244. }// END FOR ELSE
  4245. }
  4246. } // END FOR GB_QUANTITY
  4247. }
  4248. else
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4251. {
  4252. tempIndex = 2;
  4253. }
  4254. else
  4255. {
  4256. tempIndex = connectorIdInt -1;
  4257. }
  4258. for (int index = 0; index < AC_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4261. {
  4262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4264. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4265. {
  4266. //Reserved
  4267. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4268. }
  4269. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4270. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4271. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4272. {
  4273. //Reserved
  4274. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4275. result = FAIL;
  4276. goto end;
  4277. }
  4278. else
  4279. {
  4280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4283. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4284. {
  4285. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4286. result = FAIL;
  4287. goto end;
  4288. }
  4289. }//END FOR ELSE
  4290. }
  4291. }// END FOR AC_QUANTITY
  4292. }
  4293. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4294. {
  4295. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4296. {
  4297. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4298. {
  4299. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4300. system(cmdBuf);
  4301. }
  4302. }
  4303. else
  4304. {
  4305. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4306. result = FAIL;
  4307. }
  4308. }
  4309. end:
  4310. if(result == PASS)
  4311. {
  4312. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4313. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4314. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4315. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4316. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4317. }
  4318. }
  4319. void CheckSystemValue(void)
  4320. {
  4321. char filenmae[100]={0};
  4322. char str[100]={0};
  4323. int tempIndex = 0;
  4324. //===============================
  4325. // send Heartbeat
  4326. //===============================
  4327. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4328. {
  4329. //parameter for test
  4330. sendHeartbeatRequest(0);
  4331. //===========================
  4332. // Reset Waiting Time
  4333. //===========================
  4334. HeartBeatWithNOResponse += 1;
  4335. }
  4336. //===============================
  4337. // Credit deduct report
  4338. //===============================
  4339. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4340. {
  4341. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4342. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4343. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4344. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4345. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4346. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4347. }
  4348. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4349. {
  4350. OCPP_query_deduct_info();
  4351. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4352. }
  4353. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4354. {
  4355. // ClockAlign MeterValue
  4356. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4357. {
  4358. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4359. {
  4360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4361. {
  4362. tempIndex = ((gun_index==2) ? 1: 0);
  4363. }
  4364. else
  4365. {
  4366. tempIndex = gun_index;
  4367. }
  4368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4369. {
  4370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4371. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4372. {
  4373. reqClockAlignMeter[gun_index] = 1;
  4374. }
  4375. }// End for CHAdeMO
  4376. }
  4377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4378. {
  4379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4380. {
  4381. tempIndex = ((gun_index==2) ? 1: 0);
  4382. }
  4383. else
  4384. {
  4385. tempIndex = gun_index;
  4386. }
  4387. for (int index = 0; index < CCS_QUANTITY; index++)
  4388. {
  4389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4390. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4391. {
  4392. reqClockAlignMeter[gun_index] = 1;
  4393. }
  4394. } // End for CCS
  4395. }
  4396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4397. {
  4398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4399. {
  4400. tempIndex = ((gun_index==2) ? 1: 0);
  4401. }
  4402. else
  4403. {
  4404. tempIndex = gun_index;
  4405. }
  4406. for (int index = 0; index < GB_QUANTITY; index++)
  4407. {
  4408. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4410. {
  4411. reqClockAlignMeter[gun_index] = 1;
  4412. }
  4413. }// End for GB
  4414. }
  4415. else if(gunType[gun_index] == GUN_TYPE_DO)
  4416. {
  4417. tempIndex = gun_index;
  4418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4419. {
  4420. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4421. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4422. {
  4423. reqClockAlignMeter[gun_index] = 1;
  4424. }
  4425. }
  4426. }
  4427. else
  4428. {
  4429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4430. {
  4431. tempIndex = 2;
  4432. }
  4433. else
  4434. {
  4435. tempIndex = gun_index;
  4436. }
  4437. for (int index = 0; index < AC_QUANTITY; index++)
  4438. {
  4439. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4440. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4441. {
  4442. reqClockAlignMeter[gun_index] = 1;
  4443. }
  4444. }//End for AC
  4445. }
  4446. }
  4447. }
  4448. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4449. {
  4450. //==========================================
  4451. // Check remote start without connector id
  4452. //==========================================
  4453. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4454. {
  4455. int connectorIdInt = -1;
  4456. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4457. {
  4458. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4459. {
  4460. connectorIdInt = (gun_index+1);
  4461. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4462. checkRemoteStart(connectorIdInt);
  4463. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4464. break;
  4465. }
  4466. }
  4467. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4468. {
  4469. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4470. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4471. }
  4472. }
  4473. //==========================================
  4474. // csu trigger DataTransferReq
  4475. //==========================================
  4476. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4477. {
  4478. sendDataTransferRequest(gun_index);
  4479. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4480. }
  4481. //==========================================
  4482. // CSU Trigger Authorize Request
  4483. //==========================================
  4484. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4485. {
  4486. sendAuthorizeRequest(0);
  4487. authorizeRetryTimes = authorizeRetryTimes + 1;
  4488. if(authorizeRetryTimes < 3)
  4489. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4490. }
  4491. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4492. {
  4493. authorizeRetryTimes = 0;
  4494. SetOcppConnStatus(FALSE);
  4495. server_sign = FALSE;
  4496. }
  4497. 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))
  4498. {
  4499. sendAuthorizeRequest(0);
  4500. }
  4501. //==========================================
  4502. // Charger start transaction
  4503. //==========================================
  4504. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4505. {
  4506. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4507. sendStartTransactionRequest(gun_index);
  4508. refreshStartTimer(&clientTime.StartTransaction);
  4509. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4510. storeTempStopTransaction(gun_index);
  4511. }
  4512. //==========================================
  4513. // Charger stop transaction
  4514. //==========================================
  4515. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4516. {
  4517. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4518. sendStopTransactionRequest(gun_index);
  4519. OCPP_updatePeriodEnergy(gun_index);
  4520. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4521. refreshStartTimer(&clientTime.StopTransaction);
  4522. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4523. }
  4524. //==========================================
  4525. // Charger status report
  4526. //==========================================
  4527. //--- Check Mode Change ---//
  4528. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4529. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4530. {
  4531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4532. {
  4533. tempIndex = ((gun_index==2) ? 1: 0);
  4534. }
  4535. else
  4536. {
  4537. tempIndex = gun_index;
  4538. }
  4539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4542. {
  4543. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4544. {
  4545. // Sent unplug message for California pricing logic
  4546. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4547. {
  4548. uint8_t ts[36];
  4549. getNowDatetime(ts);
  4550. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4551. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4552. if(strcmp((char*)dmsVersion, "2.0")==0)
  4553. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4554. else
  4555. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4556. sendUnplugByDataTransferRequest(gun_index);
  4557. interLock.isSentUnplug[gun_index] = 1;
  4558. }
  4559. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4560. {
  4561. interLock.isSentUnplug[gun_index] = 0;
  4562. }
  4563. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4564. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4565. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4566. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4567. {
  4568. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4569. if((access(filenmae,F_OK))!=-1)
  4570. {
  4571. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4572. sprintf(str,"rm -f %s",filenmae);
  4573. system(str);
  4574. }
  4575. }
  4576. }
  4577. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4578. #if 1 // for TempStopTransaction
  4579. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4580. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4581. {
  4582. checkTempStopTransaction(gun_index);
  4583. }
  4584. #endif
  4585. }
  4586. }
  4587. }
  4588. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4591. {
  4592. tempIndex = ((gun_index==2) ? 1: 0);
  4593. }
  4594. else
  4595. {
  4596. tempIndex = gun_index;
  4597. }
  4598. for (int index = 0; index < CCS_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4601. {
  4602. 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]*/ )
  4603. {
  4604. // Sent unplug message for California pricing logic
  4605. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4606. {
  4607. uint8_t ts[36];
  4608. getNowDatetime(ts);
  4609. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4610. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4611. if(strcmp((char*)dmsVersion, "2.0")==0)
  4612. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4613. else
  4614. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4615. sendUnplugByDataTransferRequest(gun_index);
  4616. interLock.isSentUnplug[gun_index] = 1;
  4617. }
  4618. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4619. {
  4620. interLock.isSentUnplug[gun_index] = 0;
  4621. }
  4622. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4623. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4624. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4625. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4626. {
  4627. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4628. if((access(filenmae,F_OK))!=-1)
  4629. {
  4630. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4631. sprintf(str,"rm -f %s",filenmae);
  4632. system(str);
  4633. }
  4634. }
  4635. }
  4636. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4637. #if 1 // for TempStopTransaction
  4638. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4639. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4640. {
  4641. checkTempStopTransaction(gun_index);
  4642. }
  4643. #endif
  4644. }
  4645. }
  4646. }
  4647. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4650. {
  4651. tempIndex = ((gun_index==2) ? 1: 0);
  4652. }
  4653. else
  4654. {
  4655. tempIndex = gun_index;
  4656. }
  4657. for (int index = 0; index < GB_QUANTITY; index++)
  4658. {
  4659. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4660. {
  4661. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4662. {
  4663. // Sent unplug message for California pricing logic
  4664. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4665. {
  4666. uint8_t ts[36];
  4667. getNowDatetime(ts);
  4668. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4669. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4670. if(strcmp((char*)dmsVersion, "2.0")==0)
  4671. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4672. else
  4673. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4674. sendUnplugByDataTransferRequest(gun_index);
  4675. interLock.isSentUnplug[gun_index] = 1;
  4676. }
  4677. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4678. {
  4679. interLock.isSentUnplug[gun_index] = 0;
  4680. }
  4681. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4682. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4683. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4684. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4685. {
  4686. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4687. if((access(filenmae,F_OK))!=-1)
  4688. {
  4689. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4690. sprintf(str,"rm -f %s",filenmae);
  4691. system(str);
  4692. }
  4693. }
  4694. }
  4695. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4696. #if 1 // for TempStopTransaction
  4697. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4698. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4699. {
  4700. checkTempStopTransaction(gun_index);
  4701. }
  4702. #endif
  4703. }
  4704. }
  4705. }
  4706. else if(gunType[gun_index] == GUN_TYPE_DO)
  4707. {
  4708. tempIndex = gun_index;
  4709. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4710. {
  4711. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4712. {
  4713. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4714. {
  4715. // Sent unplug message for California pricing logic
  4716. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4717. {
  4718. uint8_t ts[36];
  4719. getNowDatetime(ts);
  4720. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4721. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4722. if(strcmp((char*)dmsVersion, "2.0")==0)
  4723. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4724. else
  4725. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4726. sendUnplugByDataTransferRequest(gun_index);
  4727. interLock.isSentUnplug[gun_index] = 1;
  4728. }
  4729. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4730. {
  4731. interLock.isSentUnplug[gun_index] = 0;
  4732. }
  4733. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4734. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4736. 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
  4737. {
  4738. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4739. if((access(filenmae,F_OK))!=-1)
  4740. {
  4741. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4742. sprintf(str,"rm -f %s",filenmae);
  4743. system(str);
  4744. }
  4745. }
  4746. }
  4747. 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);
  4748. #if 1 // for TempStopTransaction
  4749. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4750. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4751. {
  4752. checkTempStopTransaction(gun_index);
  4753. }
  4754. #endif
  4755. }
  4756. }
  4757. }
  4758. else
  4759. {
  4760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4761. {
  4762. tempIndex = 2;
  4763. }
  4764. else
  4765. {
  4766. tempIndex = gun_index;
  4767. }
  4768. for (int index = 0; index < AC_QUANTITY; index++)
  4769. {
  4770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4771. {
  4772. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4773. {
  4774. // Sent unplug message for California pricing logic
  4775. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4776. {
  4777. uint8_t ts[36];
  4778. getNowDatetime(ts);
  4779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4780. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4781. if(strcmp((char*)dmsVersion, "2.0")==0)
  4782. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4783. else
  4784. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4785. sendUnplugByDataTransferRequest(gun_index);
  4786. interLock.isSentUnplug[gun_index] = 1;
  4787. }
  4788. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4789. {
  4790. interLock.isSentUnplug[gun_index] = 0;
  4791. }
  4792. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4793. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4794. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4795. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4796. {
  4797. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4798. if((access(filenmae,F_OK))!=-1)
  4799. {
  4800. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4801. sprintf(str,"rm -f %s",filenmae);
  4802. system(str);
  4803. }
  4804. }
  4805. }
  4806. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4807. #if 1 // for TempStopTransaction
  4808. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4809. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4810. {
  4811. checkTempStopTransaction(gun_index);
  4812. }
  4813. #endif
  4814. }
  4815. }// END
  4816. }
  4817. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4818. (
  4819. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4820. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4821. )
  4822. )
  4823. {
  4824. sendStatusNotificationRequest(gun_index);
  4825. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4826. }
  4827. //==============================================
  4828. // TCCI reader status report
  4829. //==============================================
  4830. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4831. {
  4832. reportReaderStatus(gun_index);
  4833. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4834. }
  4835. //==============================================
  4836. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4837. //==============================================
  4838. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4839. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4840. {
  4841. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4842. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4843. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4844. }
  4845. //==============================================
  4846. // Meter report
  4847. //==============================================
  4848. // Trigger MeterValue
  4849. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4850. {
  4851. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4852. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4853. }
  4854. // Clock-aligned Meter value
  4855. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4856. {
  4857. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4858. reqClockAlignMeter[gun_index] = 0;
  4859. }
  4860. // Sample period MeterValue
  4861. 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))))
  4862. {
  4863. //check Transaction active
  4864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4865. {
  4866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4867. {
  4868. tempIndex = ((gun_index==2) ? 1: 0);
  4869. }
  4870. else
  4871. {
  4872. tempIndex = gun_index;
  4873. }
  4874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4875. {
  4876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4880. {
  4881. reqSampleMeter[gun_index] = 1;
  4882. }
  4883. }
  4884. }// End for CHAdeMO
  4885. }
  4886. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4887. {
  4888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4889. {
  4890. tempIndex = ((gun_index==2) ? 1: 0);
  4891. }
  4892. else
  4893. {
  4894. tempIndex = gun_index;
  4895. }
  4896. for (int index = 0; index < CCS_QUANTITY; index++)
  4897. {
  4898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4899. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4900. {
  4901. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4902. {
  4903. reqSampleMeter[gun_index] = 1;
  4904. }
  4905. }
  4906. } // End for CCS
  4907. }
  4908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4911. {
  4912. tempIndex = ((gun_index==2) ? 1: 0);
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < GB_QUANTITY; index++)
  4919. {
  4920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4921. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4922. {
  4923. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4924. {
  4925. reqSampleMeter[gun_index] = 1;
  4926. }
  4927. }
  4928. }// End for GB
  4929. }
  4930. else if(gunType[gun_index] == GUN_TYPE_DO)
  4931. {
  4932. tempIndex = gun_index;
  4933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4934. {
  4935. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4936. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4937. {
  4938. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4939. {
  4940. reqSampleMeter[gun_index] = 1;
  4941. }
  4942. }
  4943. }
  4944. }
  4945. else
  4946. {
  4947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4948. {
  4949. tempIndex = 2;
  4950. }
  4951. else
  4952. {
  4953. tempIndex = gun_index;
  4954. }
  4955. for (int index = 0; index < AC_QUANTITY; index++)
  4956. {
  4957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4958. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4959. {
  4960. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4961. {
  4962. reqSampleMeter[gun_index] = 1;
  4963. }
  4964. }
  4965. }//End for AC
  4966. }
  4967. if(reqSampleMeter[gun_index] == 1)
  4968. {
  4969. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4970. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4971. storeTempStopTransaction(gun_index);
  4972. reqSampleMeter[gun_index] = 0;
  4973. }
  4974. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4975. }
  4976. //==============================================
  4977. // Check Connector reserved
  4978. //==============================================
  4979. //===============================
  4980. // Check if Reserve is expired
  4981. //===============================
  4982. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4983. {
  4984. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4985. {
  4986. DEBUG_INFO("reserve expired.\n");
  4987. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4988. }
  4989. }//END OF Check if Reserve is expired
  4990. //==========================================
  4991. // csu trigger FirmwareStatusNotificationReq
  4992. //==========================================
  4993. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4994. {
  4995. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4996. }
  4997. //==========================================
  4998. // csu trigger DiagnosticsStatusNotificationReq
  4999. //==========================================
  5000. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5001. {
  5002. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5003. }
  5004. //==========================================
  5005. // csu trigger CancelReservationConf
  5006. //==========================================
  5007. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5008. {
  5009. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5010. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5011. }
  5012. //==========================================
  5013. // csu trigger ChangeAvailabilityConf
  5014. //==========================================
  5015. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5016. {
  5017. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5018. }
  5019. //==========================================
  5020. // csu trigger UnlockConnectorConf
  5021. //==========================================
  5022. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5023. {
  5024. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5025. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5026. }
  5027. //==========================================
  5028. // csu trigger ReserveNowConf
  5029. //==========================================
  5030. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5031. {
  5032. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5033. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5034. }
  5035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5036. {
  5037. sendSignCertificateRequest();
  5038. }
  5039. }
  5040. }
  5041. //==========================================
  5042. // send request routine
  5043. //==========================================
  5044. int sendAuthorizeRequest(int gun_index)
  5045. {
  5046. mtrace();
  5047. int result = FAIL;
  5048. char message[100]={0};
  5049. char guid[37];
  5050. char tempdata[65]={0};
  5051. DEBUG_INFO("sendAuthorizeRequest...\n");
  5052. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5053. //Local Authorize
  5054. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5055. {
  5056. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5057. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5058. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5059. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5060. result = PASS;
  5061. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5062. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5063. authorizeRetryTimes = 0;
  5064. return result;
  5065. }
  5066. 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))||
  5067. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5068. {
  5069. // Query from cache
  5070. DEBUG_INFO("Authorize from cache.\n");
  5071. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5072. // Query from list
  5073. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5074. {
  5075. DEBUG_INFO("Authorize from list.\n");
  5076. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5077. }
  5078. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5079. {
  5080. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5081. {
  5082. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5083. }
  5084. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5085. {
  5086. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5087. }
  5088. if(!GetOcppConnStatus())
  5089. {
  5090. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5092. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5093. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5094. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5095. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5096. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5097. authorizeRetryTimes = 0;
  5098. return result;
  5099. }
  5100. }
  5101. else
  5102. {
  5103. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5104. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5105. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5106. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5107. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5108. else
  5109. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5110. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5111. result = PASS;
  5112. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5113. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5114. authorizeRetryTimes = 0;
  5115. return result;
  5116. }
  5117. }
  5118. //initialize struct Authorize
  5119. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5120. //get data from shared memory
  5121. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5122. random_uuid(guid);
  5123. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5124. LWS_Send(message);
  5125. sprintf(tempdata, "Authorize,%d", gun_index);
  5126. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5127. {
  5128. result = PASS;
  5129. DEBUG_INFO("Authorize mapItem pass\n");
  5130. }
  5131. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5132. return result;
  5133. }
  5134. int sendBootNotificationRequest(void)
  5135. {
  5136. mtrace();
  5137. int result = FAIL;
  5138. char message[500]={0}, payload[700]={0};
  5139. char guid[37]={0};
  5140. char tempdata[65]={0};
  5141. // Fill BootNotification fields
  5142. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5143. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5144. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5145. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5146. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5147. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5148. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5149. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5150. ShmOCPP16Data->ChargeBoxId
  5151. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5152. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5153. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5154. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5155. ,ShmOCPP16Data->BootNotification.CpIccid
  5156. ,ShmOCPP16Data->BootNotification.CpImsi);
  5157. random_uuid(guid);
  5158. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5159. LWS_Send(message);
  5160. sprintf(tempdata, "BootNotification,0");
  5161. 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*/)
  5162. {
  5163. result = PASS;
  5164. }
  5165. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5166. strcpy(queuedata,message);
  5167. return result;
  5168. }
  5169. int sendDataTransferRequest(int gun_index)
  5170. {
  5171. mtrace();
  5172. char message[1000]={0};
  5173. char guid[37]={0};
  5174. char tempdata[65]={0};
  5175. int result = FAIL;
  5176. random_uuid(guid);
  5177. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5178. MESSAGE_TYPE_CALL,
  5179. guid,
  5180. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5181. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5182. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5183. LWS_Send(message);
  5184. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5186. {
  5187. result = PASS;
  5188. DEBUG_INFO("DataTransfer mapItem pass\n");
  5189. }
  5190. return result;
  5191. }
  5192. int sendUnplugByDataTransferRequest(int gun_index)
  5193. {
  5194. mtrace();
  5195. char message[1000]={0};
  5196. char guid[37]={0};
  5197. char tempdata[65]={0};
  5198. int result = FAIL;
  5199. random_uuid(guid);
  5200. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5201. (gun_index+1),
  5202. MESSAGE_TYPE_CALL,
  5203. guid,
  5204. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5205. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5206. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5207. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5208. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5209. {
  5210. result = PASS;
  5211. DEBUG_INFO("DataTransfer mapItem pass\n");
  5212. }
  5213. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5214. return result;
  5215. }
  5216. int sendDiagnosticsStatusNotificationRequest(char *status)
  5217. {
  5218. mtrace();
  5219. int result = FAIL;
  5220. char message[110]={0};
  5221. char guid[37]={0};
  5222. char tempdata[65]={0};
  5223. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5224. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5225. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5226. random_uuid(guid);
  5227. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5228. LWS_SendNow(message);
  5229. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5230. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5231. {
  5232. result = PASS;
  5233. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5234. }
  5235. //#ifdef SystemLogMessage
  5236. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5237. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5238. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5239. //#endif
  5240. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5242. //record status
  5243. if(strcmp(status,"Idle")==0)
  5244. {
  5245. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5246. }
  5247. else if(strcmp(status,"Uploaded")==0)
  5248. {
  5249. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5250. }
  5251. else if(strcmp(status,"UploadFailed")==0)
  5252. {
  5253. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5254. }
  5255. else if(strcmp(status,"Uploading")==0)
  5256. {
  5257. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5258. }
  5259. return result;
  5260. }
  5261. int sendFirmwareStatusNotificationRequest(char *status)
  5262. {
  5263. mtrace();
  5264. int result = FAIL;
  5265. char message[110]={0};
  5266. char guid[37]={0};
  5267. char tempdata[65]={0};
  5268. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5269. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5270. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5271. random_uuid(guid);
  5272. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5273. LWS_SendNow(message);
  5274. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5275. 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*/)
  5276. {
  5277. result = PASS;
  5278. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5279. }
  5280. //#ifdef SystemLogMessage
  5281. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5282. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5283. //#endif
  5284. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5285. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5286. //record status
  5287. if(strcmp(status,"Downloaded")==0)
  5288. {
  5289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5290. }
  5291. else if(strcmp(status,"DownloadFailed")==0)
  5292. {
  5293. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5294. }
  5295. else if(strcmp(status,"Downloading")==0)
  5296. {
  5297. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5298. }
  5299. else if(strcmp(status,"Idle")==0)
  5300. {
  5301. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5302. }
  5303. else if(strcmp(status,"InstallationFailed")==0)
  5304. {
  5305. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5306. }
  5307. else if(strcmp(status,"Installing")==0)
  5308. {
  5309. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5310. }
  5311. else if(strcmp(status,"Installed")==0)
  5312. {
  5313. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5314. }
  5315. return result;
  5316. }
  5317. int sendHeartbeatRequest(int gun_index)
  5318. {
  5319. mtrace();
  5320. int result = FAIL;
  5321. char message[80]={0};
  5322. char guid[37]={0};
  5323. char tempdata[65]={0};
  5324. random_uuid(guid);
  5325. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5326. , MESSAGE_TYPE_CALL
  5327. , guid );
  5328. LWS_Send(message);
  5329. sprintf(tempdata, "Heartbeat,%d", 0);
  5330. 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*/)
  5331. {
  5332. result = PASS;
  5333. }
  5334. return result;
  5335. }
  5336. int sendStartTransactionRequest(int gun_index)
  5337. {
  5338. mtrace();
  5339. int result = FAIL;
  5340. char message[250]={0};
  5341. char guid[37]={0};
  5342. struct timeval tmnow;
  5343. struct tm *tm;
  5344. char buf[28];//, usec_buf[6];
  5345. char tempdata[65]={0};
  5346. int tempIndex = 0;
  5347. DEBUG_INFO("sendStartTransactionRequest...\n");
  5348. gettimeofday(&tmnow, NULL);
  5349. time_t t;
  5350. t = time(NULL);
  5351. /*UTC time and date*/
  5352. tm = gmtime(&t);
  5353. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5354. #if 0 // remove temporally
  5355. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5356. strcat(buf,".");
  5357. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5358. strcat(buf,usec_buf);
  5359. #endif
  5360. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5362. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5363. // clear StartTransaction Response
  5364. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5365. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5366. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5367. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5368. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5369. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5371. {
  5372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5373. {
  5374. tempIndex = ((gun_index==2) ? 1: 0);
  5375. }
  5376. else
  5377. {
  5378. tempIndex = gun_index;
  5379. }
  5380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5383. {
  5384. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5385. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5386. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5387. }
  5388. }
  5389. }
  5390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5391. {
  5392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5393. {
  5394. tempIndex = ((gun_index==2) ? 1: 0);
  5395. }
  5396. else
  5397. {
  5398. tempIndex = gun_index;
  5399. }
  5400. for (int index = 0; index < CCS_QUANTITY; index++)
  5401. {
  5402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5403. {
  5404. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5405. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5406. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5407. }
  5408. }
  5409. }
  5410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5413. {
  5414. tempIndex = ((gun_index==2) ? 1: 0);
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < GB_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5423. {
  5424. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5425. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5426. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5427. }
  5428. }
  5429. }
  5430. else if(gunType[gun_index] == GUN_TYPE_DO)
  5431. {
  5432. tempIndex = gun_index;
  5433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5436. {
  5437. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5438. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5439. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5440. }
  5441. }
  5442. }
  5443. else
  5444. {
  5445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5446. {
  5447. tempIndex = 2;
  5448. }
  5449. else
  5450. {
  5451. tempIndex = gun_index;
  5452. }
  5453. for (int index = 0; index < AC_QUANTITY; index++)
  5454. {
  5455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5456. {
  5457. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5458. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5459. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5460. }
  5461. }
  5462. }
  5463. random_uuid(guid);
  5464. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5465. {
  5466. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5467. , gun_index +1
  5468. , MESSAGE_TYPE_CALL
  5469. , guid
  5470. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5471. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5472. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5473. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5474. }
  5475. else
  5476. {
  5477. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5478. , gun_index +1
  5479. , MESSAGE_TYPE_CALL
  5480. , guid
  5481. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5482. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5483. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5484. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5485. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5486. }
  5487. #if 1
  5488. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5489. 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*/)
  5490. {
  5491. result = PASS;
  5492. }
  5493. #endif
  5494. strcpy(queuedata, message);
  5495. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5496. OCPP_insert_transaction_msg(YES, queuedata);
  5497. return result;
  5498. }
  5499. int sendStatusNotificationRequest(int gun_index)
  5500. {
  5501. mtrace();
  5502. int result = FAIL;
  5503. char message[600]={0};
  5504. char guid[37];
  5505. int currentStatus = 0;
  5506. struct timeval tmnow;
  5507. struct tm *tm;
  5508. char buf[28];//, usec_buf[6];
  5509. char tempdata[65]={0};
  5510. int tempIndex = 0;
  5511. uint8_t isStateChanged = TRUE;
  5512. uint8_t isContentIllegal = TRUE;
  5513. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5514. gettimeofday(&tmnow, NULL);
  5515. time_t t;
  5516. t = time(NULL);
  5517. /*UTC time and date*/
  5518. tm = gmtime(&t);
  5519. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5520. #if 0 // remove temporally
  5521. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5522. strcat(buf,".");
  5523. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5524. strcat(buf,usec_buf);
  5525. #endif
  5526. //printf("%s",buf);
  5527. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5528. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5529. // it's option
  5530. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5531. /*
  5532. enum _SYSTEM_STATUS
  5533. {
  5534. S_BOOTING = 0,
  5535. S_IDLE, = 1
  5536. S_AUTHORIZING, =2
  5537. S_REASSIGN_CHECK, =3
  5538. S_REASSIGN, =4
  5539. S_PRECHARGE, =5
  5540. S_PREPARING_FOR_EV, =6
  5541. S_PREPARING_FOR_EVSE, =7
  5542. S_CHARGING, =8
  5543. S_TERMINATING, =9
  5544. S_COMPLETE, =10
  5545. S_ALARM, =11
  5546. S_FAULT =12
  5547. }
  5548. */
  5549. //check Transaction active
  5550. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5551. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5552. {
  5553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5554. {
  5555. tempIndex = ((gun_index==2) ? 1: 0);
  5556. }
  5557. else
  5558. {
  5559. tempIndex = gun_index;
  5560. }
  5561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5562. {
  5563. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5564. {
  5565. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5566. {
  5567. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5568. {
  5569. currentStatus = Preparing; //OCPP Status: Preparing
  5570. }
  5571. else
  5572. {
  5573. currentStatus = Available; //OCPP Status: Available
  5574. }
  5575. }
  5576. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5577. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5578. ) //S_PRECHARGE
  5579. {
  5580. currentStatus = Preparing; //OCPP Status: Preparing
  5581. }
  5582. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5583. {
  5584. currentStatus = Charging; //OCPP Status: Charging
  5585. }
  5586. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5587. {
  5588. currentStatus = Finishing; //OCPP Status: Finishing
  5589. }
  5590. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5591. {
  5592. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5593. }
  5594. 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
  5595. {
  5596. currentStatus = Unavailable; //OCPP Status: Unavailable
  5597. }
  5598. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5599. {
  5600. currentStatus = Faulted; //OCPP Status: Faulted
  5601. }
  5602. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5603. {
  5604. currentStatus = Reserved; //OCPP Status: Reserved
  5605. }
  5606. } //end of the same index
  5607. }//end of for CHAdeMO_QUANTITY
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5610. {
  5611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5612. {
  5613. tempIndex = ((gun_index==2) ? 1: 0);
  5614. }
  5615. else
  5616. {
  5617. tempIndex = gun_index;
  5618. }
  5619. for (int index = 0; index < CCS_QUANTITY; index++)
  5620. {
  5621. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5622. {
  5623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5624. {
  5625. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5626. {
  5627. currentStatus = Preparing; //OCPP Status: Preparing
  5628. }
  5629. else
  5630. {
  5631. currentStatus = Available; //OCPP Status: Available
  5632. }
  5633. }
  5634. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5635. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5636. ) //S_PRECHARGE
  5637. {
  5638. currentStatus = Preparing; //OCPP Status: Preparing
  5639. }
  5640. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5641. {
  5642. currentStatus = Charging; //OCPP Status: Charging
  5643. }
  5644. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5645. {
  5646. currentStatus = Finishing; //OCPP Status: Finishing
  5647. }
  5648. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5649. {
  5650. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5651. }
  5652. 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
  5653. {
  5654. currentStatus = Unavailable; //OCPP Status : Unavailable
  5655. }
  5656. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5657. {
  5658. currentStatus = Faulted; //OCPP Status: Faulted
  5659. }
  5660. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5661. {
  5662. currentStatus = Reserved; //OCPP Status: Reserved
  5663. }
  5664. } //end of the same index
  5665. } // end of for CCS_QUANTITY
  5666. }
  5667. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5668. {
  5669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5670. {
  5671. tempIndex = ((gun_index==2) ? 1: 0);
  5672. }
  5673. else
  5674. {
  5675. tempIndex = gun_index;
  5676. }
  5677. for (int index = 0; index < GB_QUANTITY; index++)
  5678. {
  5679. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5680. {
  5681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5682. {
  5683. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5684. {
  5685. currentStatus = Preparing; //OCPP Status: Preparing
  5686. }
  5687. else
  5688. {
  5689. currentStatus = Available; //OCPP Status: Available
  5690. }
  5691. }
  5692. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5693. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5694. ) //S_PRECHARGE
  5695. {
  5696. currentStatus = Preparing; //OCPP Status: Preparing
  5697. }
  5698. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5699. {
  5700. currentStatus = Charging; //OCPP Status: Charging
  5701. }
  5702. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5703. {
  5704. currentStatus = Finishing; //OCPP Status: Finishing
  5705. }
  5706. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5707. {
  5708. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5709. }
  5710. 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
  5711. {
  5712. currentStatus = Unavailable; //OCPP Status: Unavailable
  5713. }
  5714. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5715. {
  5716. currentStatus = Faulted; //OCPP Status: Faulted
  5717. }
  5718. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5719. {
  5720. currentStatus = Reserved; //OCPP Status: Reserved
  5721. }
  5722. } //end of the same index
  5723. } // end of for GB_QUANTITY
  5724. }
  5725. else if(gunType[gun_index] == GUN_TYPE_DO)
  5726. {
  5727. tempIndex = gun_index;
  5728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5731. {
  5732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5733. {
  5734. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5735. {
  5736. currentStatus = Preparing; //OCPP Status: Preparing
  5737. }
  5738. else
  5739. {
  5740. currentStatus = Available; //OCPP Status: Available
  5741. }
  5742. }
  5743. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5744. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5745. ) //S_PRECHARGE
  5746. {
  5747. currentStatus = Preparing; //OCPP Status: Preparing
  5748. }
  5749. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5750. {
  5751. currentStatus = Charging; //OCPP Status: Charging
  5752. }
  5753. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5754. {
  5755. currentStatus = Finishing; //OCPP Status: Finishing
  5756. }
  5757. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5758. {
  5759. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5760. }
  5761. 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
  5762. {
  5763. currentStatus = Unavailable; //OCPP Status: Unavailable
  5764. }
  5765. 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
  5766. {
  5767. currentStatus = Faulted; //OCPP Status: Faulted
  5768. }
  5769. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5770. {
  5771. currentStatus = Reserved; //OCPP Status: Reserved
  5772. }
  5773. } //end of the same index
  5774. }
  5775. }
  5776. else
  5777. {
  5778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5779. {
  5780. tempIndex = 2;
  5781. }
  5782. else
  5783. {
  5784. tempIndex = gun_index;
  5785. }
  5786. for (int index = 0; index < AC_QUANTITY; index++)
  5787. {
  5788. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5789. {
  5790. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5791. {
  5792. 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))
  5793. {
  5794. currentStatus = Preparing; //OCPP Status: Preparing
  5795. }
  5796. else
  5797. {
  5798. currentStatus = Available; //OCPP Status: Available
  5799. }
  5800. }
  5801. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5802. {
  5803. currentStatus = Preparing; //OCPP Status: Preparing
  5804. }
  5805. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5806. {
  5807. currentStatus = Charging; //OCPP Status: Charging
  5808. }
  5809. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5810. {
  5811. currentStatus = Finishing; //OCPP Status: Finishing
  5812. }
  5813. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5814. {
  5815. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5816. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5817. else
  5818. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5819. }
  5820. 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
  5821. {
  5822. currentStatus = Unavailable; //OCPP Status: Unavailable
  5823. }
  5824. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5825. {
  5826. currentStatus = Faulted; //OCPP Status: Faulted
  5827. }
  5828. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5829. {
  5830. currentStatus = Reserved; //OCPP Status: Reserved
  5831. }
  5832. }//end of the same index
  5833. }//end of for AC_QUANTITY
  5834. }
  5835. //it's option
  5836. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5837. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5838. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5839. {
  5840. isStateChanged = FALSE;
  5841. }
  5842. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5843. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5844. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5845. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5846. isContentIllegal = TRUE;
  5847. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5848. {
  5849. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5850. {
  5851. isContentIllegal = FALSE;
  5852. break;
  5853. }
  5854. }
  5855. if(isContentIllegal)
  5856. {
  5857. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5858. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5859. }
  5860. random_uuid(guid);
  5861. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5862. , MESSAGE_TYPE_CALL
  5863. , guid
  5864. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5865. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5866. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5867. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5868. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5869. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5870. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5871. if((server_sign == TRUE) && isStateChanged)
  5872. {
  5873. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5874. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5875. LWS_Send(message);
  5876. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5877. 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*/)
  5878. {
  5879. //DEBUG_ERROR("statusNotification mapitem pass");
  5880. result = PASS;
  5881. }
  5882. }
  5883. else
  5884. {
  5885. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5886. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5887. result = PASS;
  5888. }
  5889. return result;
  5890. }
  5891. int sendStopTransactionRequest(int gun_index)
  5892. {
  5893. mtrace();
  5894. int result = FAIL;
  5895. //char message[1500]={0};
  5896. char guid[37]={0};
  5897. char tempdata[65]={0};
  5898. int tempIndex = 0;
  5899. char TempStopTransaction[256];
  5900. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5901. //int idx_sample=0;
  5902. DEBUG_INFO("sendStopTransactionRequest \n");
  5903. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5904. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5905. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5906. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5907. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5908. {
  5909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5910. {
  5911. tempIndex = ((gun_index==2) ? 1: 0);
  5912. }
  5913. else
  5914. {
  5915. tempIndex = gun_index;
  5916. }
  5917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5918. {
  5919. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5920. {
  5921. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5922. }
  5923. }// END OF CHAdeMO_QUANTITY
  5924. }
  5925. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5926. {
  5927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5928. {
  5929. tempIndex = ((gun_index==2) ? 1: 0);
  5930. }
  5931. else
  5932. {
  5933. tempIndex = gun_index;
  5934. }
  5935. for (int index = 0; index < CCS_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5938. {
  5939. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5940. }
  5941. }// END OF CCS_QUANTITY
  5942. }
  5943. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5944. {
  5945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5946. {
  5947. tempIndex = ((gun_index==2) ? 1: 0);
  5948. }
  5949. else
  5950. {
  5951. tempIndex = gun_index;
  5952. }
  5953. for (int index = 0; index < GB_QUANTITY; index++)
  5954. {
  5955. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5956. {
  5957. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5958. }
  5959. }// END OF GB_QUANTITY
  5960. }
  5961. else if(gunType[gun_index] == GUN_TYPE_DO)
  5962. {
  5963. tempIndex = gun_index;
  5964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5965. {
  5966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5967. {
  5968. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5969. }
  5970. }// END OF GB_QUANTITY
  5971. }
  5972. else
  5973. {
  5974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5975. {
  5976. tempIndex = 2;
  5977. }
  5978. else
  5979. {
  5980. tempIndex = gun_index;
  5981. }
  5982. for (int index = 0; index < AC_QUANTITY; index++)
  5983. {
  5984. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5985. {
  5986. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5987. }
  5988. }// END OF AC_QUANTITY
  5989. }
  5990. //====================================== Stop Transaction Time =====================================================
  5991. struct timeval tmnow;
  5992. struct tm *tm;
  5993. char buf[28];//, usec_buf[6];
  5994. gettimeofday(&tmnow, NULL);
  5995. time_t t;
  5996. t = time(NULL);
  5997. /*UTC time and date*/
  5998. tm = gmtime(&t);
  5999. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6001. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6002. random_uuid(guid);
  6003. /***********************************transactionData******************************************************/
  6004. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6006. //=================================
  6007. // Transaction_Begin
  6008. //=================================
  6009. //=================================
  6010. // Transaction_End
  6011. //=================================
  6012. // ================================= Current.Import L1 ===============================================
  6013. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6014. {
  6015. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6016. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6017. {
  6018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6019. {
  6020. tempIndex = ((gun_index==2) ? 1: 0);
  6021. }
  6022. else
  6023. {
  6024. tempIndex = gun_index;
  6025. }
  6026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6031. }
  6032. }// End of for CHAdeMO_QUANTITY
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6034. }
  6035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6038. {
  6039. tempIndex = ((gun_index==2) ? 1: 0);
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < CCS_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6050. }
  6051. }// End of for CCS_QUANTITY
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6053. }
  6054. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6055. {
  6056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6057. {
  6058. tempIndex = ((gun_index==2) ? 1: 0);
  6059. }
  6060. else
  6061. {
  6062. tempIndex = gun_index;
  6063. }
  6064. for (int index = 0; index < GB_QUANTITY; index++)
  6065. {
  6066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6067. {
  6068. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6069. }
  6070. }// End of for GB_QUANTITY
  6071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6072. }
  6073. else if(gunType[gun_index] == GUN_TYPE_DO)
  6074. {
  6075. tempIndex = gun_index;
  6076. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6077. {
  6078. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6079. {
  6080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6081. }
  6082. }
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6084. }
  6085. else
  6086. {
  6087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6088. {
  6089. tempIndex = 2;
  6090. }
  6091. else
  6092. {
  6093. tempIndex = gun_index;
  6094. }
  6095. for (int index = 0; index < AC_QUANTITY; index++)
  6096. {
  6097. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6098. {
  6099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6100. }
  6101. }// End of for AC_QUANTITY
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6103. }
  6104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6109. }
  6110. // ================================= Energy.Active.Import.Interval ==============================================
  6111. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6112. {
  6113. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6127. {
  6128. 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
  6129. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6130. }
  6131. }// END OF CHAdeMO_QUANTITY
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6137. {
  6138. tempIndex = ((gun_index==2) ? 1: 0);
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < CCS_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6147. {
  6148. 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
  6149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6150. }
  6151. }// END OF CCS_QUANTITY
  6152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6153. }
  6154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6155. {
  6156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6157. {
  6158. tempIndex = ((gun_index==2) ? 1: 0);
  6159. }
  6160. else
  6161. {
  6162. tempIndex = gun_index;
  6163. }
  6164. for (int index = 0; index < GB_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6167. {
  6168. 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
  6169. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6170. }
  6171. }// END OF GB_QUANTITY
  6172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_DO)
  6175. {
  6176. tempIndex = gun_index;
  6177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6180. {
  6181. 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
  6182. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6183. }
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6186. }
  6187. else
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6190. {
  6191. tempIndex = 2;
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < AC_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6200. {
  6201. 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
  6202. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6203. }
  6204. }// END OF AC_QUANTITY
  6205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6206. }
  6207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6212. }
  6213. //=================================== Power.Active.Import ==================================================
  6214. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6215. {
  6216. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6218. {
  6219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6220. {
  6221. tempIndex = ((gun_index==2) ? 1: 0);
  6222. }
  6223. else
  6224. {
  6225. tempIndex = gun_index;
  6226. }
  6227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6232. }
  6233. } // End for CHAdeMO_QUANTITY
  6234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6235. }
  6236. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6237. {
  6238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6239. {
  6240. tempIndex = ((gun_index==2) ? 1: 0);
  6241. }
  6242. else
  6243. {
  6244. tempIndex = gun_index;
  6245. }
  6246. for (int index = 0; index < CCS_QUANTITY; index++)
  6247. {
  6248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6249. {
  6250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6251. }
  6252. } // END for CCS_QUANTITY
  6253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6254. }
  6255. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6256. {
  6257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6258. {
  6259. tempIndex = ((gun_index==2) ? 1: 0);
  6260. }
  6261. else
  6262. {
  6263. tempIndex = gun_index;
  6264. }
  6265. for (int index = 0; index < GB_QUANTITY; index++)
  6266. {
  6267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6268. {
  6269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6270. }
  6271. }// END for GB_QUANTITY
  6272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6273. }
  6274. else if(gunType[gun_index] == GUN_TYPE_DO)
  6275. {
  6276. tempIndex = gun_index;
  6277. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6278. {
  6279. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6280. {
  6281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6282. }
  6283. }
  6284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6285. }
  6286. else
  6287. {
  6288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6289. {
  6290. tempIndex = 2;
  6291. }
  6292. else
  6293. {
  6294. tempIndex = gun_index;
  6295. }
  6296. for (int index = 0; index < AC_QUANTITY; index++)
  6297. {
  6298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6299. {
  6300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6301. }
  6302. } // END for AC_QUANTITY
  6303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6304. }
  6305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6310. }
  6311. //============================ Voltage L1 ====================================
  6312. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6313. {
  6314. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6316. {
  6317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6318. {
  6319. tempIndex = ((gun_index==2) ? 1: 0);
  6320. }
  6321. else
  6322. {
  6323. tempIndex = gun_index;
  6324. }
  6325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6326. {
  6327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6328. {
  6329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6330. }
  6331. } // END OF FOR CHAdeMO_QUANTITY
  6332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6333. }
  6334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6335. {
  6336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6337. {
  6338. tempIndex = ((gun_index==2) ? 1: 0);
  6339. }
  6340. else
  6341. {
  6342. tempIndex = gun_index;
  6343. }
  6344. for (int index = 0; index < CCS_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6349. }
  6350. } // END OF FOR CCS_QUANTITY
  6351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6352. }
  6353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6356. {
  6357. tempIndex = ((gun_index==2) ? 1: 0);
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < GB_QUANTITY; index++)
  6364. {
  6365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6366. {
  6367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6368. }
  6369. } // END OF FOR GB_QUANTITY
  6370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6371. }
  6372. else if(gunType[gun_index] == GUN_TYPE_DO)
  6373. {
  6374. tempIndex = gun_index;
  6375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6376. {
  6377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6378. {
  6379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6380. }
  6381. }
  6382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6383. }
  6384. else
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6387. {
  6388. tempIndex = 2;
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < AC_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6397. {
  6398. 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
  6399. }
  6400. } // END OF FOR AC_QUANTITY
  6401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6402. }
  6403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6408. }
  6409. //====================== End SoC ================================
  6410. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6411. {
  6412. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6413. 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))
  6414. {
  6415. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6416. {
  6417. tempIndex = ((gun_index==2) ? 1: 0);
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6424. {
  6425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6430. }
  6431. }
  6432. }
  6433. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6434. {
  6435. for (int index = 0; index < CCS_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6438. {
  6439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6440. }
  6441. }
  6442. }
  6443. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6444. {
  6445. for (int index = 0; index < GB_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6450. }
  6451. }
  6452. }
  6453. else if(gunType[gun_index] == GUN_TYPE_DO)
  6454. {
  6455. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6456. {
  6457. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6458. {
  6459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6460. }
  6461. }
  6462. }
  6463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6469. } // END FOR DC CASE
  6470. }
  6471. // ================================= Current.Import L2 ===============================================
  6472. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6473. {
  6474. // AC 3 phse L2 current
  6475. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6476. {
  6477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6478. {
  6479. tempIndex = 2;
  6480. }
  6481. else
  6482. {
  6483. tempIndex = gun_index;
  6484. }
  6485. for (int index = 0; index < AC_QUANTITY; index++)
  6486. {
  6487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6488. {
  6489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6490. }
  6491. }// End of for AC_QUANTITY
  6492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6493. }
  6494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6499. }
  6500. // ================================= Current.Import L3 ===============================================
  6501. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6502. {
  6503. // AC 3 phse L3 current
  6504. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6505. {
  6506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6507. {
  6508. tempIndex = 2;
  6509. }
  6510. else
  6511. {
  6512. tempIndex = gun_index;
  6513. }
  6514. for (int index = 0; index < AC_QUANTITY; index++)
  6515. {
  6516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6517. {
  6518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6519. }
  6520. }// End of for AC_QUANTITY
  6521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6522. }
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6528. }
  6529. //============================ Voltage L2 ====================================
  6530. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6531. {
  6532. // AC 3 phse L2 voltage
  6533. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6534. {
  6535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6536. {
  6537. tempIndex = 2;
  6538. }
  6539. else
  6540. {
  6541. tempIndex = gun_index;
  6542. }
  6543. for (int index = 0; index < AC_QUANTITY; index++)
  6544. {
  6545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6546. {
  6547. 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
  6548. }
  6549. } // END OF FOR AC_QUANTITY
  6550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6551. }
  6552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6557. }
  6558. //============================ Voltage L3 ====================================
  6559. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6560. {
  6561. // AC 3 phse L3 voltage
  6562. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6563. {
  6564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6565. {
  6566. tempIndex = 2;
  6567. }
  6568. else
  6569. {
  6570. tempIndex = gun_index;
  6571. }
  6572. for (int index = 0; index < AC_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6575. {
  6576. 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
  6577. }
  6578. } // END OF FOR AC_QUANTITY
  6579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6580. }
  6581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6586. }
  6587. //====================== Start SoC ================================
  6588. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6589. {
  6590. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6591. 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))
  6592. {
  6593. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6594. {
  6595. tempIndex = ((gun_index==2) ? 1: 0);
  6596. }
  6597. else
  6598. {
  6599. tempIndex = gun_index;
  6600. }
  6601. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6602. {
  6603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6604. {
  6605. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6606. {
  6607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6608. }
  6609. }
  6610. }
  6611. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6612. {
  6613. for (int index = 0; index < CCS_QUANTITY; index++)
  6614. {
  6615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6616. {
  6617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6618. }
  6619. }
  6620. }
  6621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6622. {
  6623. for (int index = 0; index < GB_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6626. {
  6627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6628. }
  6629. }
  6630. }
  6631. else if(gunType[gun_index] == GUN_TYPE_DO)
  6632. {
  6633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6634. {
  6635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6636. {
  6637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6638. }
  6639. }
  6640. }
  6641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6647. } // END FOR DC CASE
  6648. }
  6649. //================================================ Message create ====================================================
  6650. json_object *StopTransaction = json_object_new_object();
  6651. json_object *transactionDatas = json_object_new_array();
  6652. json_object *sampledValues = json_object_new_array();
  6653. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6654. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6655. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6656. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6657. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6658. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6659. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6660. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6661. {
  6662. json_object *transactionData = json_object_new_object();
  6663. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6664. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6665. {
  6666. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6667. {
  6668. json_object *sampledValue = json_object_new_object();
  6669. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6670. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6671. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6672. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6673. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6674. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6675. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6676. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6677. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6678. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6679. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6680. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6681. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6682. json_object_array_add(sampledValues, sampledValue);
  6683. }
  6684. }
  6685. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6686. json_object_array_add(transactionDatas, transactionData);
  6687. }
  6688. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6689. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6690. ,MESSAGE_TYPE_CALL
  6691. ,guid
  6692. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6693. json_object_put(StopTransaction);
  6694. #if 1 // for TempStopTransaction
  6695. //Delete TempStopTransaction
  6696. if((access(TempStopTransaction,F_OK))!=-1)
  6697. {
  6698. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6699. }
  6700. #endif
  6701. #if 1
  6702. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6703. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6704. {
  6705. result = PASS;
  6706. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6707. }
  6708. #endif
  6709. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6710. OCPP_insert_transaction_msg(NO, queuedata);
  6711. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6712. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6713. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6714. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6715. {
  6716. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6717. }
  6718. //for test
  6719. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6720. return result;
  6721. }
  6722. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6723. {
  6724. mtrace();
  6725. int result = FAIL;
  6726. char guid[37]={0};
  6727. char tempdata[65]={0};
  6728. int tempIndex = 0;
  6729. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6730. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6731. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6732. //set value
  6733. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6734. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6735. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6736. -1);
  6737. random_uuid(guid);
  6738. //UTC Date time
  6739. struct timeval tmnow;
  6740. struct tm *tm;
  6741. char buf[28];//, usec_buf[6];
  6742. gettimeofday(&tmnow, NULL);
  6743. time_t t;
  6744. t = time(NULL);
  6745. /*UTC time and date*/
  6746. tm = gmtime(&t);
  6747. if(dataType == ReadingContext_Sample_Clock)
  6748. {
  6749. struct tm *tmTarget;
  6750. struct timeb tbTarget;
  6751. tbTarget.time = mktime(tm);
  6752. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6753. tmTarget = gmtime(&tbTarget.time);
  6754. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6755. }
  6756. else
  6757. {
  6758. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6759. }
  6760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6761. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6762. //********************************(1)Current.Import L1************************************************/
  6763. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6764. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6765. (dataType == ReadingContext_Trigger))
  6766. {
  6767. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6769. {
  6770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6771. {
  6772. tempIndex = ((gun_index==2) ? 1: 0);
  6773. }
  6774. else
  6775. {
  6776. tempIndex = gun_index;
  6777. }
  6778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6781. {
  6782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6783. }
  6784. }
  6785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6786. }
  6787. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6788. {
  6789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6790. {
  6791. tempIndex = ((gun_index==2) ? 1: 0);
  6792. }
  6793. else
  6794. {
  6795. tempIndex = gun_index;
  6796. }
  6797. for (int index = 0; index < CCS_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6800. {
  6801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6802. }
  6803. }
  6804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6805. }
  6806. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6807. {
  6808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6809. {
  6810. tempIndex = ((gun_index==2) ? 1: 0);
  6811. }
  6812. else
  6813. {
  6814. tempIndex = gun_index;
  6815. }
  6816. for (int index = 0; index < GB_QUANTITY; index++)
  6817. {
  6818. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6819. {
  6820. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6821. }
  6822. }
  6823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6824. }
  6825. else if(gunType[gun_index] == GUN_TYPE_DO)
  6826. {
  6827. tempIndex = gun_index;
  6828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6831. {
  6832. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6833. }
  6834. }
  6835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6836. }
  6837. else
  6838. {
  6839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6840. {
  6841. tempIndex = 2;
  6842. }
  6843. else
  6844. {
  6845. tempIndex = gun_index;
  6846. }
  6847. for (int index = 0; index < AC_QUANTITY; index++)
  6848. {
  6849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6850. {
  6851. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6852. }
  6853. }
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6855. }
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6861. }
  6862. //********************************(2)Energy.Active.Import.Register ************************************************/
  6863. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6864. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6865. (dataType == ReadingContext_Trigger))
  6866. {
  6867. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6868. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6869. {
  6870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6871. {
  6872. tempIndex = ((gun_index==2) ? 1: 0);
  6873. }
  6874. else
  6875. {
  6876. tempIndex = gun_index;
  6877. }
  6878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6879. {
  6880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6881. {
  6882. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6883. }
  6884. }
  6885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6886. }
  6887. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6888. {
  6889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6890. {
  6891. tempIndex = ((gun_index==2) ? 1: 0);
  6892. }
  6893. else
  6894. {
  6895. tempIndex = gun_index;
  6896. }
  6897. for (int index = 0; index < CCS_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6900. {
  6901. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6902. }
  6903. }
  6904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6905. }
  6906. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6907. {
  6908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6909. {
  6910. tempIndex = ((gun_index==2) ? 1: 0);
  6911. }
  6912. else
  6913. {
  6914. tempIndex = gun_index;
  6915. }
  6916. for (int index = 0; index < GB_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6921. }
  6922. }
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6924. }
  6925. else if(gunType[gun_index] == GUN_TYPE_DO)
  6926. {
  6927. tempIndex = gun_index;
  6928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6929. {
  6930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6931. {
  6932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6933. }
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6936. }
  6937. else
  6938. {
  6939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6940. {
  6941. tempIndex = 2;
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. for (int index = 0; index < AC_QUANTITY; index++)
  6948. {
  6949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6950. {
  6951. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6952. }
  6953. }
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6955. }
  6956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6961. }
  6962. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6963. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6964. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6965. (dataType == ReadingContext_Trigger))
  6966. {
  6967. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6968. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6969. {
  6970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6971. {
  6972. tempIndex = ((gun_index==2) ? 1: 0);
  6973. }
  6974. else
  6975. {
  6976. tempIndex = gun_index;
  6977. }
  6978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6979. {
  6980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6981. {
  6982. if(dataType == ReadingContext_Sample_Clock)
  6983. {
  6984. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6985. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6986. }
  6987. else if(dataType == ReadingContext_Sample_Periodic)
  6988. {
  6989. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6990. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6991. }
  6992. else
  6993. {
  6994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6995. }
  6996. }
  6997. } // END OF FOR CHAdeMO_QUANTITY
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6999. }
  7000. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7001. {
  7002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7003. {
  7004. tempIndex = ((gun_index==2) ? 1: 0);
  7005. }
  7006. else
  7007. {
  7008. tempIndex = gun_index;
  7009. }
  7010. for (int index = 0; index < CCS_QUANTITY; index++)
  7011. {
  7012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7013. {
  7014. if(dataType == ReadingContext_Sample_Clock)
  7015. {
  7016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7017. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7018. }
  7019. else if(dataType == ReadingContext_Sample_Periodic)
  7020. {
  7021. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7022. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7023. }
  7024. else
  7025. {
  7026. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7027. }
  7028. }
  7029. } // END OF CCS_QUANTITY
  7030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7031. }
  7032. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7035. {
  7036. tempIndex = ((gun_index==2) ? 1: 0);
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < GB_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7045. {
  7046. if(dataType == ReadingContext_Sample_Clock)
  7047. {
  7048. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7050. }
  7051. else if(dataType == ReadingContext_Sample_Periodic)
  7052. {
  7053. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7054. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7055. }
  7056. else
  7057. {
  7058. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7059. }
  7060. }
  7061. } // END OF GB_QUANTITY
  7062. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7063. }
  7064. else if(gunType[gun_index] == GUN_TYPE_DO)
  7065. {
  7066. tempIndex = gun_index;
  7067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7068. {
  7069. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7070. {
  7071. if(dataType == ReadingContext_Sample_Clock)
  7072. {
  7073. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7074. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7075. }
  7076. else if(dataType == ReadingContext_Sample_Periodic)
  7077. {
  7078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7079. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7080. }
  7081. else
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7084. }
  7085. }
  7086. }
  7087. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7088. }
  7089. else
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7092. {
  7093. tempIndex = 2;
  7094. }
  7095. else
  7096. {
  7097. tempIndex = gun_index;
  7098. }
  7099. for (int index = 0; index < AC_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7102. {
  7103. if(dataType == ReadingContext_Sample_Clock)
  7104. {
  7105. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7106. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7107. }
  7108. else if(dataType == ReadingContext_Sample_Periodic)
  7109. {
  7110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7111. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7112. }
  7113. else
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7116. }
  7117. }
  7118. }
  7119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7120. }
  7121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7126. }
  7127. //********************************(4)Power.Active.Import************************************************/
  7128. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7129. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7130. (dataType == ReadingContext_Trigger))
  7131. {
  7132. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7133. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7134. {
  7135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7136. {
  7137. tempIndex = ((gun_index==2) ? 1: 0);
  7138. }
  7139. else
  7140. {
  7141. tempIndex = gun_index;
  7142. }
  7143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7144. {
  7145. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7146. {
  7147. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7148. }
  7149. } // END OF FOR
  7150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7151. }
  7152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7153. {
  7154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7155. {
  7156. tempIndex = ((gun_index==2) ? 1: 0);
  7157. }
  7158. else
  7159. {
  7160. tempIndex = gun_index;
  7161. }
  7162. for (int index = 0; index < CCS_QUANTITY; index++)
  7163. {
  7164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7165. {
  7166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7167. }
  7168. }
  7169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7170. }
  7171. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7172. {
  7173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7174. {
  7175. tempIndex = ((gun_index==2) ? 1: 0);
  7176. }
  7177. else
  7178. {
  7179. tempIndex = gun_index;
  7180. }
  7181. for (int index = 0; index < GB_QUANTITY; index++)
  7182. {
  7183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7184. {
  7185. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7186. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7187. }
  7188. }
  7189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7190. }
  7191. else if(gunType[gun_index] == GUN_TYPE_DO)
  7192. {
  7193. tempIndex = gun_index;
  7194. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7197. {
  7198. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7200. }
  7201. }
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7203. }
  7204. else
  7205. {
  7206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7207. {
  7208. tempIndex = 2;
  7209. }
  7210. else
  7211. {
  7212. tempIndex = gun_index;
  7213. }
  7214. for (int index = 0; index < AC_QUANTITY; index++)
  7215. {
  7216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7217. {
  7218. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7219. }
  7220. }
  7221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7222. }
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7228. }
  7229. //***********************************************(5)VOLTAGE L1******************************************************/
  7230. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7231. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7232. (dataType == ReadingContext_Trigger))
  7233. {
  7234. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7235. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7236. {
  7237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7238. {
  7239. tempIndex = ((gun_index==2) ? 1: 0);
  7240. }
  7241. else
  7242. {
  7243. tempIndex = gun_index;
  7244. }
  7245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7246. {
  7247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7248. {
  7249. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7250. }
  7251. }
  7252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7253. }
  7254. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7255. {
  7256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7257. {
  7258. tempIndex = ((gun_index==2) ? 1: 0);
  7259. }
  7260. else
  7261. {
  7262. tempIndex = gun_index;
  7263. }
  7264. for (int index = 0; index < CCS_QUANTITY; index++)
  7265. {
  7266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7267. {
  7268. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7269. }
  7270. }
  7271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7272. }
  7273. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7274. {
  7275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7276. {
  7277. tempIndex = ((gun_index==2) ? 1: 0);
  7278. }
  7279. else
  7280. {
  7281. tempIndex = gun_index;
  7282. }
  7283. for (int index = 0; index < GB_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7286. {
  7287. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7288. }
  7289. }
  7290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7291. }
  7292. else if(gunType[gun_index] == GUN_TYPE_DO)
  7293. {
  7294. tempIndex = gun_index;
  7295. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7296. {
  7297. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7298. {
  7299. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7300. }
  7301. }
  7302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7303. }
  7304. else
  7305. {
  7306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7307. {
  7308. tempIndex = 2;
  7309. }
  7310. else
  7311. {
  7312. tempIndex = gun_index;
  7313. }
  7314. for (int index = 0; index < AC_QUANTITY; index++)
  7315. {
  7316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7317. {
  7318. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7319. }
  7320. }
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7322. }
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7328. }
  7329. //***********************************************(6)SOC******************************************************/
  7330. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7331. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7332. (dataType == ReadingContext_Trigger))
  7333. {
  7334. 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))
  7335. {
  7336. //idx_sample=5;
  7337. //sampledValue = NULL;
  7338. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7339. {
  7340. tempIndex = ((gun_index==2) ? 1: 0);
  7341. }
  7342. else
  7343. {
  7344. tempIndex = gun_index;
  7345. }
  7346. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7347. {
  7348. //tempIndex = ((gun_index==2) ? 1: 0);
  7349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7350. {
  7351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7352. {
  7353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7354. }
  7355. }
  7356. }
  7357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7358. {
  7359. //tempIndex = ((gun_index==2) ? 1: 0);
  7360. for (int index = 0; index < CCS_QUANTITY; index++)
  7361. {
  7362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7363. {
  7364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7365. }
  7366. }
  7367. }
  7368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7369. {
  7370. //tempIndex = ((gun_index==2) ? 1: 0);
  7371. for (int index = 0; index < GB_QUANTITY; index++)
  7372. {
  7373. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7374. {
  7375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7376. }
  7377. }
  7378. }
  7379. else if(gunType[gun_index] == GUN_TYPE_DO)
  7380. {
  7381. //tempIndex = ((gun_index==2) ? 1: 0);
  7382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7383. {
  7384. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7385. {
  7386. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7387. }
  7388. }
  7389. }
  7390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7396. }
  7397. }
  7398. //********************************(7)Current.Import L2************************************************/
  7399. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7400. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7401. (dataType == ReadingContext_Trigger))
  7402. {
  7403. // Only for AC 3 phase
  7404. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7405. {
  7406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7407. {
  7408. tempIndex = 2;
  7409. }
  7410. else
  7411. {
  7412. tempIndex = gun_index;
  7413. }
  7414. for (int index = 0; index < AC_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7417. {
  7418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7419. }
  7420. }
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7422. }
  7423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7428. }
  7429. //********************************(8)Current.Import L3************************************************/
  7430. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7431. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7432. (dataType == ReadingContext_Trigger))
  7433. {
  7434. // Only for AC 3 phase
  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[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7450. }
  7451. }
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7453. }
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7459. }
  7460. //***********************************************(9)VOLTAGE L2******************************************************/
  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[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7480. }
  7481. }
  7482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7483. }
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7489. }
  7490. //***********************************************(10)VOLTAGE L3******************************************************/
  7491. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7492. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7493. (dataType == ReadingContext_Trigger))
  7494. {
  7495. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7496. {
  7497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7498. {
  7499. tempIndex = 2;
  7500. }
  7501. else
  7502. {
  7503. tempIndex = gun_index;
  7504. }
  7505. for (int index = 0; index < AC_QUANTITY; index++)
  7506. {
  7507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7508. {
  7509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7510. }
  7511. }
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7519. }
  7520. //***********************************************(11)Current.Offered******************************************************/
  7521. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7522. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7523. (dataType == ReadingContext_Trigger))
  7524. {
  7525. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7526. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7527. {
  7528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7529. {
  7530. tempIndex = ((gun_index==2) ? 1: 0);
  7531. }
  7532. else
  7533. {
  7534. tempIndex = gun_index;
  7535. }
  7536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7537. {
  7538. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7539. {
  7540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7541. }
  7542. } // END OF FOR CHAdeMO_QUANTITY
  7543. }
  7544. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7545. {
  7546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7547. {
  7548. tempIndex = ((gun_index==2) ? 1: 0);
  7549. }
  7550. else
  7551. {
  7552. tempIndex = gun_index;
  7553. }
  7554. for (int index = 0; index < CCS_QUANTITY; index++)
  7555. {
  7556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7557. {
  7558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7559. }
  7560. } // END OF CCS_QUANTITY
  7561. }
  7562. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7563. {
  7564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7565. {
  7566. tempIndex = ((gun_index==2) ? 1: 0);
  7567. }
  7568. else
  7569. {
  7570. tempIndex = gun_index;
  7571. }
  7572. for (int index = 0; index < GB_QUANTITY; index++)
  7573. {
  7574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7575. {
  7576. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7577. }
  7578. } // END OF GB_QUANTITY
  7579. }
  7580. else if(gunType[gun_index] == GUN_TYPE_DO)
  7581. {
  7582. tempIndex = gun_index;
  7583. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7584. {
  7585. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7586. {
  7587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7588. }
  7589. }
  7590. }
  7591. else
  7592. {
  7593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7594. {
  7595. tempIndex = 2;
  7596. }
  7597. else
  7598. {
  7599. tempIndex = gun_index;
  7600. }
  7601. for (int index = 0; index < AC_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7604. {
  7605. uint16_t currentOffer;
  7606. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7607. {
  7608. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7609. }
  7610. else
  7611. {
  7612. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7613. }
  7614. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7615. }
  7616. }
  7617. }
  7618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7623. }
  7624. //***********************************************(12)Power.Offered******************************************************/
  7625. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7626. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7627. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7628. {
  7629. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7631. {
  7632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7633. {
  7634. tempIndex = ((gun_index==2) ? 1: 0);
  7635. }
  7636. else
  7637. {
  7638. tempIndex = gun_index;
  7639. }
  7640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7641. {
  7642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7643. {
  7644. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7645. }
  7646. } // END OF FOR CHAdeMO_QUANTITY
  7647. }
  7648. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7649. {
  7650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7651. {
  7652. tempIndex = ((gun_index==2) ? 1: 0);
  7653. }
  7654. else
  7655. {
  7656. tempIndex = gun_index;
  7657. }
  7658. for (int index = 0; index < CCS_QUANTITY; index++)
  7659. {
  7660. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7661. {
  7662. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7663. }
  7664. } // END OF CCS_QUANTITY
  7665. }
  7666. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7667. {
  7668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7669. {
  7670. tempIndex = ((gun_index==2) ? 1: 0);
  7671. }
  7672. else
  7673. {
  7674. tempIndex = gun_index;
  7675. }
  7676. for (int index = 0; index < GB_QUANTITY; index++)
  7677. {
  7678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7679. {
  7680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7681. }
  7682. } // END OF GB_QUANTITY
  7683. }
  7684. else if(gunType[gun_index] == GUN_TYPE_DO)
  7685. {
  7686. tempIndex = gun_index;
  7687. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7688. {
  7689. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7690. {
  7691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7692. }
  7693. }
  7694. }
  7695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7696. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7700. }
  7701. // Message create ====================================================================================================
  7702. if(TRUE)
  7703. {
  7704. json_object *MeterValueReq = json_object_new_object();
  7705. json_object *MeterValues = json_object_new_array();
  7706. json_object *sampledValues = json_object_new_array();
  7707. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7708. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7709. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7710. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7711. {
  7712. json_object *MeterValue = json_object_new_object();
  7713. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7714. {
  7715. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7716. {
  7717. json_object *sampledValue = json_object_new_object();
  7718. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7719. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7720. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7721. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7722. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7723. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7724. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7725. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7726. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7727. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7728. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7729. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7730. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7731. json_object_array_add(sampledValues, sampledValue);
  7732. }
  7733. }
  7734. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7735. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7736. json_object_array_add(MeterValues, MeterValue);
  7737. }
  7738. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7739. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7740. ,gun_index + 1
  7741. ,MESSAGE_TYPE_CALL
  7742. ,guid
  7743. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7744. json_object_put(MeterValueReq);
  7745. }
  7746. // Put request guid to hash map
  7747. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7748. 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*/)
  7749. {
  7750. result = PASS;
  7751. //DEBUG_INFO("MeterValues mapitem pass\n");
  7752. }
  7753. if((dataType != ReadingContext_Trigger) &&
  7754. (dataType != ReadingContext_Sample_Clock) &&
  7755. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7756. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7757. else
  7758. {
  7759. if(FirstHeartBeat)
  7760. LWS_Send(queuedata +2);
  7761. }
  7762. return result;
  7763. }
  7764. int sendLogStatusNotificationRequest(char *status)
  7765. {
  7766. mtrace();
  7767. int result = PASS;
  7768. char message[4096]={0};
  7769. char guid[37]={0};
  7770. char tempdata[128]={0};
  7771. json_object *LogStatusNotification = json_object_new_object();
  7772. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7773. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7774. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7775. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7776. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7777. random_uuid(guid);
  7778. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7779. json_object_put(LogStatusNotification);
  7780. LWS_Send(message);
  7781. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7782. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7783. {
  7784. result = PASS;
  7785. }
  7786. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7787. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7788. return result;
  7789. }
  7790. int sendSecurityEventNotificationRequest()
  7791. {
  7792. mtrace();
  7793. int result = PASS;
  7794. char message[4096]={0};
  7795. char guid[37]={0};
  7796. char tempdata[128]={0};
  7797. json_object *SecurityEventNotification = json_object_new_object();
  7798. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7799. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7800. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7801. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7802. random_uuid(guid);
  7803. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7804. json_object_put(SecurityEventNotification);
  7805. LWS_Send(message);
  7806. sprintf(tempdata, "SecurityEventNotification,0");
  7807. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7808. {
  7809. result = PASS;
  7810. }
  7811. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7812. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7813. return result;
  7814. }
  7815. int sendSignCertificateRequest()
  7816. {
  7817. mtrace();
  7818. int result = PASS;
  7819. char message[4096]={0};
  7820. char guid[37]={0};
  7821. char tempdata[128]={0};
  7822. json_object *SignCertificate = json_object_new_object();
  7823. DEBUG_INFO("sendSignCertificateRequest...\n");
  7824. // Read csr file content
  7825. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7826. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7827. char *line = NULL;
  7828. size_t len = 0;
  7829. while(getline(&line, &len, fp) != -1)
  7830. {
  7831. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7832. {
  7833. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7834. }
  7835. }
  7836. fclose(fp);
  7837. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7838. random_uuid(guid);
  7839. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7840. json_object_put(SignCertificate);
  7841. LWS_Send(message);
  7842. sprintf(tempdata, "SignCertificate,0");
  7843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7844. {
  7845. result = PASS;
  7846. }
  7847. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7848. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7849. return result;
  7850. }
  7851. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7852. {
  7853. mtrace();
  7854. int result = PASS;
  7855. char message[110]={0};
  7856. char guid[37]={0};
  7857. char tempdata[65]={0};
  7858. json_object *FirmwareStatusNotification = json_object_new_object();
  7859. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7860. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7861. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7862. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7863. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7864. random_uuid(guid);
  7865. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7866. json_object_put(FirmwareStatusNotification);
  7867. LWS_Send(message);
  7868. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7869. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7870. {
  7871. result = PASS;
  7872. }
  7873. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7874. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7875. return result;
  7876. }
  7877. //==========================================
  7878. // send confirm routine
  7879. //==========================================
  7880. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7881. {
  7882. mtrace();
  7883. int result = FAIL;
  7884. char message[100]={0};
  7885. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7887. LWS_Send(message);
  7888. result = TRUE;
  7889. return result;
  7890. }
  7891. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7892. {
  7893. mtrace();
  7894. int result = FAIL;
  7895. char message[100]={0};
  7896. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7897. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7898. LWS_Send(message);
  7899. result = TRUE;
  7900. return result;
  7901. }
  7902. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7903. {
  7904. mtrace();
  7905. int result = FAIL;
  7906. char message[100]={0};
  7907. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7908. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7909. LWS_Send(message);
  7910. result = TRUE;
  7911. return result;
  7912. }
  7913. int sendClearCacheConfirmation(char *uuid,char *payload)
  7914. {
  7915. mtrace();
  7916. int result = FAIL;
  7917. char message[500]={0};
  7918. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7919. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7920. LWS_Send(message);
  7921. return result;
  7922. }
  7923. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7924. {
  7925. mtrace();
  7926. int result = FAIL;
  7927. char message[500]={0};
  7928. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7929. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7930. LWS_Send(message);
  7931. return result;
  7932. }
  7933. int sendDataTransferConfirmation(char *uuid,char *payload)
  7934. {
  7935. mtrace();
  7936. char statusStr[20]={0};
  7937. char dataStr[10]={0};
  7938. char sstr[20]={0};
  7939. int c = 0;
  7940. char *loc;
  7941. int result = FAIL;
  7942. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7943. /**********************status**************************/
  7944. loc = strstr(payload, "status");
  7945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7946. c = 0;
  7947. while (loc[3+strlen("status")+c] != '\"')
  7948. {
  7949. sstr[c] = loc[3+strlen("status")+c];
  7950. c++;
  7951. }
  7952. sstr[c] = '\0';
  7953. strcpy(statusStr, sstr);
  7954. /**********************data**************************/
  7955. loc = strstr(payload, "data");
  7956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7957. c = 0;
  7958. while (loc[3+strlen("data")+c] != '\"')
  7959. {
  7960. sstr[c] = loc[3+strlen("data")+c];
  7961. c++;
  7962. }
  7963. sstr[c] = '\0';
  7964. strcpy(dataStr, sstr);
  7965. return result;
  7966. }
  7967. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7968. {
  7969. mtrace();
  7970. int result = FAIL;
  7971. char message[1000]={0};
  7972. int CompositeScheduleIndex = 0;
  7973. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7974. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7975. if(nPeriod == 0)
  7976. {
  7977. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7978. {
  7979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7980. ,MESSAGE_TYPE_CALLRESULT
  7981. ,uuid
  7982. ,payload
  7983. ,connectorIdInt);
  7984. }
  7985. else
  7986. {
  7987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7988. ,MESSAGE_TYPE_CALLRESULT
  7989. ,uuid
  7990. ,payload
  7991. ,connectorIdInt
  7992. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7993. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7994. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7995. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7996. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7997. }
  7998. }
  7999. else
  8000. {
  8001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8002. ,MESSAGE_TYPE_CALLRESULT
  8003. ,uuid
  8004. ,payload
  8005. ,connectorIdInt
  8006. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8007. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8008. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8009. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8010. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8011. {
  8012. if (idx_sample == 0)
  8013. {
  8014. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8015. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8016. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8017. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8018. }
  8019. else
  8020. {
  8021. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8022. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8023. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8024. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8025. }
  8026. }
  8027. sprintf(message + strlen(message), "]}}]");
  8028. }
  8029. LWS_Send(message);
  8030. result = TRUE;
  8031. return result;
  8032. }
  8033. int sendGetConfigurationConfirmation(char *uuid)
  8034. {
  8035. mtrace();
  8036. int result = FAIL;
  8037. int MaxKeySupported = 0;
  8038. int sentConfigurationNumber= 0;
  8039. int sentunConfigurationNumber= 0;
  8040. char message[1024*10]={0};
  8041. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8042. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8043. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8044. ,MESSAGE_TYPE_CALLRESULT
  8045. ,uuid );
  8046. //configuration key
  8047. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8048. {
  8049. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8050. {
  8051. if (sentConfigurationNumber == 0)
  8052. {
  8053. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8054. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8055. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8056. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8057. }
  8058. else
  8059. {
  8060. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8061. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8062. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8063. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8064. }
  8065. sentConfigurationNumber = sentConfigurationNumber + 1;
  8066. }
  8067. }
  8068. sprintf(message + strlen(message), "]");
  8069. if(UnknownKeynum != 0)
  8070. {
  8071. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8072. //unkown key
  8073. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8074. {
  8075. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8076. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8077. if(sentunConfigurationNumber == 0)
  8078. {
  8079. sprintf(message + strlen(message), "\"%s\""
  8080. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8081. }
  8082. else
  8083. {
  8084. sprintf(message + strlen(message), ",\"%s\""
  8085. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8086. }
  8087. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8088. }
  8089. sprintf(message + strlen(message), "]");
  8090. }
  8091. sprintf(message + strlen(message), "}]");
  8092. LWS_Send(message);
  8093. return result;
  8094. }
  8095. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8096. {
  8097. mtrace();
  8098. int result = FAIL;
  8099. char message[400]={0};
  8100. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8101. if(strcmp(payload,"")==0)
  8102. {
  8103. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8104. }
  8105. else
  8106. {
  8107. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8108. }
  8109. LWS_Send(message);
  8110. result = TRUE;
  8111. return result;
  8112. }
  8113. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8114. {
  8115. mtrace();
  8116. int result = FAIL;
  8117. char message[80]={0};
  8118. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8119. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8120. LWS_Send(message);
  8121. result = TRUE;
  8122. return result;
  8123. }
  8124. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8125. {
  8126. mtrace();
  8127. int result = FAIL;
  8128. char message[80]={0};
  8129. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8130. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8131. LWS_Send(message);
  8132. result = TRUE;
  8133. return result;
  8134. }
  8135. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8136. {
  8137. mtrace();
  8138. int result = FAIL;
  8139. char message[80]={0};
  8140. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8141. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8142. LWS_Send(message);
  8143. result = TRUE;
  8144. return result;
  8145. }
  8146. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8147. {
  8148. mtrace();
  8149. int result = FAIL;
  8150. char message[80]={0};
  8151. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8152. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8153. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8154. LWS_Send(message);
  8155. result = TRUE;
  8156. return result;
  8157. }
  8158. int sendResetConfirmation(char *uuid,char *payload)
  8159. {
  8160. mtrace();
  8161. int result = FAIL;
  8162. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8163. char message[80]={0};
  8164. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8165. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8166. LWS_Send(message);
  8167. result = TRUE;
  8168. return result;
  8169. }
  8170. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8171. {
  8172. mtrace();
  8173. int result = FAIL;
  8174. char message[500]={0};
  8175. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8176. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8177. LWS_Send(message);
  8178. result = TRUE;
  8179. return result;
  8180. }
  8181. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8182. {
  8183. mtrace();
  8184. int result = FAIL;
  8185. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8186. char message[80]={0};
  8187. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8189. LWS_Send(message);
  8190. result = TRUE;
  8191. return result;
  8192. }
  8193. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8194. {
  8195. mtrace();
  8196. int result = FAIL;
  8197. char message[80]={0};
  8198. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8199. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8200. LWS_Send(message);
  8201. result = TRUE;
  8202. return result;
  8203. }
  8204. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8205. {
  8206. mtrace();
  8207. int result = FAIL;
  8208. char message[80]={0};
  8209. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8210. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8211. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8212. LWS_Send(message);
  8213. result = TRUE;
  8214. return result;
  8215. }
  8216. int sendUpdateFirmwareConfirmation(char *uuid)
  8217. {
  8218. mtrace();
  8219. int result = FAIL;
  8220. char message[60]={0};
  8221. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8222. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8223. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8224. LWS_Send(message);
  8225. result = TRUE;
  8226. return result;
  8227. }
  8228. int sendCertificateSignedConfirmation(char *uuid)
  8229. {
  8230. mtrace();
  8231. int result = PASS;
  8232. char message[4096]={0};
  8233. json_object *CertificateSigned = json_object_new_object();
  8234. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8235. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8236. sprintf(message,"[%d,\"%s\",%s]"
  8237. ,MESSAGE_TYPE_CALLRESULT
  8238. ,uuid
  8239. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8240. json_object_put(CertificateSigned);
  8241. LWS_Send(message);
  8242. return result;
  8243. }
  8244. int sendDeleteCertificateConfirmation(char *uuid)
  8245. {
  8246. mtrace();
  8247. int result = PASS;
  8248. char message[4096]={0};
  8249. json_object *DeleteCertificate = json_object_new_object();
  8250. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8251. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8252. sprintf(message,"[%d,\"%s\",%s]"
  8253. ,MESSAGE_TYPE_CALLRESULT
  8254. ,uuid
  8255. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8256. json_object_put(DeleteCertificate);
  8257. LWS_Send(message);
  8258. return result;
  8259. }
  8260. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8261. {
  8262. mtrace();
  8263. int result = PASS;
  8264. char message[4096]={0};
  8265. json_object *ExtendedTriggerMessage = json_object_new_object();
  8266. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8267. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8268. sprintf(message,"[%d,\"%s\",%s]"
  8269. ,MESSAGE_TYPE_CALLRESULT
  8270. ,uuid
  8271. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8272. json_object_put(ExtendedTriggerMessage);
  8273. LWS_Send(message);
  8274. return result;
  8275. }
  8276. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8277. {
  8278. mtrace();
  8279. int result = PASS;
  8280. char message[4096]={0};
  8281. json_object *GetInstalledCertificateIds = json_object_new_object();
  8282. json_object *certificateHashDataDatas = json_object_new_array();
  8283. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8284. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8285. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8286. {
  8287. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8288. {
  8289. json_object *certificateHashData = json_object_new_object();
  8290. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8291. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8292. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8293. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8294. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8295. }
  8296. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8297. }
  8298. else
  8299. {
  8300. json_object_put(certificateHashDataDatas);
  8301. }
  8302. sprintf(message,"[%d,\"%s\",%s]"
  8303. ,MESSAGE_TYPE_CALLRESULT
  8304. ,uuid
  8305. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8306. json_object_put(GetInstalledCertificateIds);
  8307. LWS_Send(message);
  8308. return result;
  8309. }
  8310. int sendGetLogConfirmation(char *uuid)
  8311. {
  8312. mtrace();
  8313. int result = PASS;
  8314. char message[4096]={0};
  8315. json_object *GetLog = json_object_new_object();
  8316. DEBUG_INFO("sendGetLogConfirmation...\n");
  8317. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8318. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8319. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8320. sprintf(message,"[%d,\"%s\",%s]"
  8321. ,MESSAGE_TYPE_CALLRESULT
  8322. ,uuid
  8323. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8324. json_object_put(GetLog);
  8325. LWS_Send(message);
  8326. return result;
  8327. }
  8328. int sendInstallCertificateConfirmation(char *uuid)
  8329. {
  8330. mtrace();
  8331. int result = PASS;
  8332. char message[4096]={0};
  8333. json_object *InstallCertificate = json_object_new_object();
  8334. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8335. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8336. sprintf(message,"[%d,\"%s\",%s]"
  8337. ,MESSAGE_TYPE_CALLRESULT
  8338. ,uuid
  8339. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8340. json_object_put(InstallCertificate);
  8341. LWS_Send(message);
  8342. return result;
  8343. }
  8344. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8345. {
  8346. mtrace();
  8347. int result = PASS;
  8348. char message[4096]={0};
  8349. json_object *SignedUpdateFirmware = json_object_new_object();
  8350. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8351. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8352. sprintf(message,"[%d,\"%s\",%s]"
  8353. ,MESSAGE_TYPE_CALLRESULT
  8354. ,uuid
  8355. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8356. json_object_put(SignedUpdateFirmware);
  8357. LWS_Send(message);
  8358. return result;
  8359. }
  8360. int sendUnknownConfirmation(char *uuid)
  8361. {
  8362. mtrace();
  8363. int result = PASS;
  8364. char message[256]={0};
  8365. DEBUG_INFO("sendUnknownConfirmation...\n");
  8366. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8367. LWS_Send(message);
  8368. return result;
  8369. }
  8370. //==========================================
  8371. // Handle server request routine Start
  8372. //==========================================
  8373. int handleCancelReservationRequest(char *uuid, char *payload)
  8374. {
  8375. mtrace();
  8376. int result = FAIL;
  8377. int gunNO = 0;
  8378. int reservationIdInt = -1;
  8379. char comfirmstr[20];
  8380. DEBUG_INFO("handleCancelReservationRequest...\n");
  8381. json_object *CancelReservation;
  8382. CancelReservation = json_tokener_parse(payload);
  8383. if(!is_error(CancelReservation))
  8384. {
  8385. // Required data
  8386. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8387. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8388. }
  8389. json_object_put(CancelReservation);
  8390. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8391. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8392. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8393. if(reservationIdInt != -1)
  8394. {
  8395. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8396. //check Transaction active
  8397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8399. {
  8400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8401. {
  8402. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8403. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8404. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8405. {
  8406. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8407. }
  8408. else
  8409. {
  8410. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8411. }
  8412. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8413. goto end;
  8414. }
  8415. }
  8416. for (int index = 0; index < CCS_QUANTITY; index++)
  8417. {
  8418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8419. {
  8420. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8421. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8422. if(gunType[2] == GUN_TYPE_CCS)
  8423. {
  8424. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8425. }
  8426. else
  8427. {
  8428. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8429. }
  8430. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8431. goto end;
  8432. }
  8433. }
  8434. for (int index = 0; index < GB_QUANTITY; index++)
  8435. {
  8436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8437. {
  8438. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8439. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8440. if(gunType[2] == GUN_TYPE_GBT)
  8441. {
  8442. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8443. }
  8444. else
  8445. {
  8446. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8447. }
  8448. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8449. goto end;
  8450. }
  8451. }
  8452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8453. {
  8454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8455. {
  8456. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8457. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8458. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8459. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8460. goto end;
  8461. }
  8462. }
  8463. for (int index = 0; index < AC_QUANTITY; index++)
  8464. {
  8465. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8466. {
  8467. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8468. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8470. {
  8471. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8472. }
  8473. else
  8474. {
  8475. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8476. }
  8477. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8478. goto end;
  8479. }
  8480. }
  8481. }
  8482. //The reservationId does NOT match the reservationId
  8483. sendCancelReservationConfirmation(uuid, comfirmstr);
  8484. end:
  8485. // Fill in ocpp packet uuid
  8486. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8487. return result;
  8488. }
  8489. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8490. {
  8491. mtrace();
  8492. int result = FAIL;
  8493. int gunIndex = -1;
  8494. char typeStr[16]={0};
  8495. char comfirmstr[20];
  8496. int specificId = FALSE;
  8497. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8498. json_object *ChangeAvailability;
  8499. ChangeAvailability = json_tokener_parse(payload);
  8500. if(!is_error(ChangeAvailability))
  8501. {
  8502. // Required data
  8503. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8504. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8505. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8506. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8507. }
  8508. json_object_put(ChangeAvailability);
  8509. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8510. {
  8511. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8512. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8513. }
  8514. else if(gunIndex == 0)
  8515. {
  8516. for(int i=0; i < gunTotalNumber; i++)
  8517. {
  8518. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8519. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8520. }
  8521. }
  8522. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8524. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8525. {
  8526. specificId = TRUE;
  8527. }
  8528. if(specificId == FALSE)
  8529. goto end;
  8530. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8531. {
  8532. //----------------------gunIndex is 0 ------------------------------------------------//
  8533. if(gunIndex == 0)
  8534. {
  8535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8536. {
  8537. for(int i=0; i < gunTotalNumber; i++)
  8538. {
  8539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8540. {
  8541. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8542. {
  8543. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8544. {
  8545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8546. goto end;
  8547. }
  8548. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8549. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8550. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8551. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8552. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8553. {
  8554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8555. goto end;
  8556. }
  8557. }
  8558. }//END FOR CHAdeMO_QUANTITY
  8559. for (int index = 0; index < CCS_QUANTITY; index++)
  8560. {
  8561. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8562. {
  8563. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8564. {
  8565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8566. goto end;
  8567. }
  8568. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8571. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8572. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8573. {
  8574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8575. goto end;
  8576. }
  8577. }
  8578. }//END FOR CCS_QUANTITY
  8579. for (int index = 0; index < GB_QUANTITY; index++)
  8580. {
  8581. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8582. {
  8583. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8584. {
  8585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8586. goto end;
  8587. }
  8588. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8591. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8592. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8593. {
  8594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8595. goto end;
  8596. }
  8597. }
  8598. }// END FOR GB_QUANTITY
  8599. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8600. {
  8601. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8602. {
  8603. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8604. {
  8605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8606. goto end;
  8607. }
  8608. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8610. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8611. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8612. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8613. {
  8614. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8615. goto end;
  8616. }
  8617. }
  8618. }// END FOR GENERAL_GUN_QUANTITY
  8619. for (int index = 0; index < AC_QUANTITY; index++)
  8620. {
  8621. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8622. {
  8623. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8624. {
  8625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8626. goto end;
  8627. }
  8628. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8631. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8633. {
  8634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8635. goto end;
  8636. }
  8637. }
  8638. }//END FOR AC_QUANTITY
  8639. }// END FOR gunTotalNumber
  8640. }
  8641. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8642. {
  8643. for(int i=0; i < gunTotalNumber; i++)
  8644. {
  8645. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8646. {
  8647. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8648. goto end;
  8649. }
  8650. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8653. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8654. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8655. {
  8656. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8657. goto end;
  8658. }
  8659. }
  8660. }
  8661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8662. goto end;
  8663. }
  8664. //----------------------gunIndex is not 0 ------------------------------------------------//
  8665. //check Transaction active
  8666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8667. {
  8668. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8669. {
  8670. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8671. {
  8672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8673. goto end;
  8674. }
  8675. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8678. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8679. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8680. {
  8681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8682. goto end;
  8683. }
  8684. else
  8685. {
  8686. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8688. goto end;
  8689. }
  8690. }
  8691. }//END FOR CHAdeMO_QUANTITY
  8692. for (int index = 0; index < CCS_QUANTITY; index++)
  8693. {
  8694. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8695. {
  8696. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8699. goto end;
  8700. }
  8701. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8703. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8704. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8705. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8708. goto end;
  8709. }
  8710. else
  8711. {
  8712. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8713. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8714. goto end;
  8715. }
  8716. }
  8717. }//END FOR CCS_QUANTITY
  8718. for (int index = 0; index < GB_QUANTITY; index++)
  8719. {
  8720. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8721. {
  8722. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8723. {
  8724. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8725. goto end;
  8726. }
  8727. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8729. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8730. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8731. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8732. {
  8733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8734. goto end;
  8735. }
  8736. else
  8737. {
  8738. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8739. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8740. goto end;
  8741. }
  8742. }
  8743. }// END FOR GB_QUANTITY
  8744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8745. {
  8746. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8747. {
  8748. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8749. {
  8750. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8751. goto end;
  8752. }
  8753. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8757. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8758. {
  8759. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8760. goto end;
  8761. }
  8762. else
  8763. {
  8764. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8765. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8766. goto end;
  8767. }
  8768. }
  8769. }// END FOR GENERAL_GUN_QUANTITY
  8770. for (int index = 0; index < AC_QUANTITY; index++)
  8771. {
  8772. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8773. {
  8774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8775. {
  8776. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8777. goto end;
  8778. }
  8779. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8781. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8782. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8783. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8784. {
  8785. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8786. goto end;
  8787. }
  8788. else
  8789. {
  8790. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8792. goto end;
  8793. }
  8794. }
  8795. }//END FOR AC_QUANTITY
  8796. }//END FOR AvailabilityTypeStr[Inoperative]
  8797. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8798. {
  8799. //----------------------gunIndex is 0 ------------------------------------------------//
  8800. if(gunIndex == 0)
  8801. {
  8802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8803. {
  8804. for(int i=0; i < gunTotalNumber; i++)
  8805. {
  8806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8807. {
  8808. 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
  8809. {
  8810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8811. goto end;
  8812. }
  8813. }//END FOR CHAdeMO_QUANTITY
  8814. for (int index = 0; index < CCS_QUANTITY; index++)
  8815. {
  8816. 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
  8817. {
  8818. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8819. goto end;
  8820. }
  8821. }//END FOR CCS_QUANTITY
  8822. for (int index = 0; index < GB_QUANTITY; index++)
  8823. {
  8824. 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
  8825. {
  8826. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8827. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8828. goto end;
  8829. }
  8830. }// END FOR GB_QUANTITY
  8831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8832. {
  8833. 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
  8834. {
  8835. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8837. goto end;
  8838. }
  8839. }// END FOR GENERAL_GUN_QUANTITY
  8840. for (int index = 0; index < AC_QUANTITY; index++)
  8841. {
  8842. 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
  8843. {
  8844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8845. goto end;
  8846. }
  8847. }//END FOR CHAdeMO_QUANTITY
  8848. }// END FOR gunTotalNumber
  8849. }
  8850. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8851. {
  8852. for(int i=0; i < gunTotalNumber; i++)
  8853. {
  8854. for (int index = 0; index < AC_QUANTITY; index++)
  8855. {
  8856. 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
  8857. {
  8858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8859. goto end;
  8860. }
  8861. }//END FOR CHAdeMO_QUANTITY
  8862. } // END FOR gunTotalNumber
  8863. }
  8864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8865. goto end;
  8866. }
  8867. //----------------------gunIndex is not 0 ------------------------------------------------//
  8868. //check Transaction active
  8869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8870. {
  8871. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8872. {
  8873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8874. goto end;
  8875. }
  8876. }//END FOR CHAdeMO_QUANTITY
  8877. for (int index = 0; index < CCS_QUANTITY; index++)
  8878. {
  8879. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8880. {
  8881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8882. goto end;
  8883. }
  8884. }//END FOR CCS_QUANTITY
  8885. for (int index = 0; index < GB_QUANTITY; index++)
  8886. {
  8887. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8888. {
  8889. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8890. goto end;
  8891. }
  8892. }// END FOR GB_QUANTITY
  8893. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8894. {
  8895. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8896. {
  8897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8898. goto end;
  8899. }
  8900. }// END FOR GENERAL_GUN_QUANTITY
  8901. for (int index = 0; index < AC_QUANTITY; index++)
  8902. {
  8903. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8904. {
  8905. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8906. goto end;
  8907. }
  8908. }//END FOR AC_QUANTITY
  8909. }//END FOR AvailabilityTypeStr[Operative]
  8910. end:
  8911. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8912. {
  8913. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8914. }
  8915. else
  8916. {
  8917. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8918. }
  8919. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8920. {
  8921. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8922. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8923. }
  8924. else if(gunIndex == 0)
  8925. {
  8926. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8927. {
  8928. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8929. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8930. }
  8931. }
  8932. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8933. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8934. return result;
  8935. }
  8936. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8937. {
  8938. mtrace();
  8939. int valueInvalid = NO;
  8940. int result = FAIL;
  8941. char keystr[40]={0};
  8942. char valuestr[501]={0}; //value should be limited in 500 bytes
  8943. char comfirmstr[20]={0};
  8944. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8945. json_object *ChangeConfiguration;
  8946. ChangeConfiguration = json_tokener_parse(payload);
  8947. if(!is_error(ChangeConfiguration))
  8948. {
  8949. // Required data
  8950. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8951. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8952. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8953. {
  8954. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8955. }
  8956. else
  8957. {
  8958. valueInvalid = YES;
  8959. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8960. }
  8961. }
  8962. json_object_put(ChangeConfiguration);
  8963. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8964. {
  8965. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8966. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8967. }
  8968. else
  8969. {
  8970. int status = setKeyValue(keystr, valuestr);
  8971. switch(status)
  8972. {
  8973. case ConfigurationStatus_Accepted:
  8974. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8975. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8976. StoreConfigurationTable();
  8977. break;
  8978. case RebootRequired:
  8979. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8980. StoreConfigurationTable();
  8981. break;
  8982. case NotSupported:
  8983. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8984. break;
  8985. case ConfigurationStatus_Rejected:
  8986. default:
  8987. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8988. break;
  8989. }
  8990. }
  8991. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8992. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8993. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8994. {
  8995. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8996. SetOcppConnStatus(FALSE);
  8997. }
  8998. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8999. {
  9000. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9001. }
  9002. return result;
  9003. }
  9004. int handleClearCacheRequest(char *uuid, char *payload)
  9005. {
  9006. mtrace();
  9007. int result = FAIL;
  9008. char comfirmstr[20];
  9009. char rmFileCmd[100]={0};
  9010. struct stat stats;
  9011. DEBUG_INFO("handleClearCacheRequest...\n");
  9012. stat("/Storage/OCPP", &stats);
  9013. // Check for directory existence
  9014. if (S_ISDIR(stats.st_mode) == 1)
  9015. {}
  9016. else
  9017. {
  9018. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9019. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9020. system(rmFileCmd);
  9021. }
  9022. if(OCPP_cleanLocalCache())
  9023. {
  9024. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9025. }
  9026. else
  9027. {
  9028. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9029. }
  9030. sendClearCacheConfirmation(uuid, comfirmstr);
  9031. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9032. return result;
  9033. }
  9034. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9035. {
  9036. mtrace();
  9037. int result = FAIL;
  9038. int resultRename;
  9039. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9040. char chargingProfilePurposeStr[26]={0};
  9041. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9042. char tempchargingProfilePurposeStr[26]={0};
  9043. char str[100]={0};
  9044. char fname[200]={0};
  9045. char comfirmstr[20]={0};
  9046. char word[1600]={0};
  9047. int clearflag = FALSE;
  9048. int chargingProfileIdIsNULL = FALSE;
  9049. int connectorIsNULL = FALSE;
  9050. int chargingProfilePurposeIsNULL = FALSE;
  9051. int stackLevelIsNULL = FALSE;
  9052. //int GotoEnd = FALSE;
  9053. FILE *fptr1, *fptr2;
  9054. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9055. int n_chargingProfile=0;
  9056. int isEmptyFile = FALSE;
  9057. char sLineWord[1600]={0};
  9058. char chargingProfiles[10][100]={0};
  9059. int ChargeProfileCount = 0;
  9060. int ch;
  9061. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9062. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9063. json_object *ClearChargingProfile;
  9064. ClearChargingProfile = json_tokener_parse(payload);
  9065. if(!is_error(ClearChargingProfile))
  9066. {
  9067. // Optional data
  9068. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9069. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9070. else
  9071. chargingProfileIdIsNULL = TRUE;
  9072. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9073. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9074. else
  9075. connectorIsNULL = TRUE;
  9076. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9077. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9078. else
  9079. chargingProfilePurposeIsNULL = TRUE;
  9080. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9081. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9082. else
  9083. stackLevelIsNULL = TRUE;
  9084. }
  9085. json_object_put(ClearChargingProfile);
  9086. if(connectorIsNULL == FALSE)
  9087. {
  9088. switch(connectorIdInt)
  9089. {
  9090. case 0:
  9091. if(chargingProfilePurposeIsNULL == TRUE)
  9092. {
  9093. int l = 0;
  9094. strcpy(fname, ChargePointMaxProfile_JSON);
  9095. if((access(fname,F_OK))!=-1)
  9096. {
  9097. strcpy(chargingProfiles[l], fname);
  9098. l = l + 1;
  9099. }
  9100. strcpy(fname, TxDefaultProfile_0_JSON);
  9101. if((access(fname,F_OK))!=-1)
  9102. {
  9103. strcpy(chargingProfiles[l], fname);
  9104. l = l + 1;
  9105. }
  9106. ChargeProfileCount = l;
  9107. }
  9108. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9109. {
  9110. strcpy(fname, ChargePointMaxProfile_JSON);
  9111. if((access(fname,F_OK))!=-1)
  9112. {
  9113. strcpy(chargingProfiles[0], fname);
  9114. ChargeProfileCount = 1;
  9115. }
  9116. }
  9117. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9118. {
  9119. strcpy(fname, TxDefaultProfile_0_JSON);
  9120. if((access(fname,F_OK))!=-1)
  9121. {
  9122. strcpy(chargingProfiles[0], fname);
  9123. ChargeProfileCount = 1;
  9124. }
  9125. }
  9126. break;
  9127. default:
  9128. if(chargingProfilePurposeIsNULL == TRUE)
  9129. {
  9130. int m = 0;
  9131. memset(fname, 0, ARRAY_SIZE(fname));
  9132. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9133. if((access(fname,F_OK))!=-1)
  9134. {
  9135. strcpy(chargingProfiles[m], fname);
  9136. m = m + 1;
  9137. }
  9138. memset(fname, 0, ARRAY_SIZE(fname));
  9139. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9140. if((access(fname,F_OK))!=-1)
  9141. {
  9142. strcpy(chargingProfiles[m], fname);
  9143. m = m + 1;
  9144. }
  9145. ChargeProfileCount = m;
  9146. }
  9147. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9148. {
  9149. //strcpy(fname, TxDefaultProfile_1_JSON);
  9150. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9151. if((access(fname,F_OK))!=-1)
  9152. {
  9153. strcpy(chargingProfiles[0], fname);
  9154. ChargeProfileCount = 1;
  9155. }
  9156. }
  9157. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9158. {
  9159. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9160. if((access(fname,F_OK))!=-1)
  9161. {
  9162. strcpy(chargingProfiles[0], fname);
  9163. ChargeProfileCount = 1;
  9164. }
  9165. //strcpy(fname, TxProfile_1_JSON);
  9166. }
  9167. //strcpy(fname, ChargePointMaxProfile_JSON );
  9168. break;
  9169. }
  9170. }
  9171. else // Check all Charging Profiles
  9172. {
  9173. int i = 0;
  9174. char fnametemp[200]={0};
  9175. ChargeProfileCount = 0;
  9176. //Check ChargePointMaxProfile.json exit
  9177. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9178. {
  9179. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9180. i = i + 1;
  9181. }
  9182. //Check TxDefaultProfile_0.json exit
  9183. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9184. {
  9185. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9186. i = i + 1;
  9187. }
  9188. //Check TxDefaultProfile_%d.json
  9189. for(int j=1; j <= gunTotalNumber; j++)
  9190. {
  9191. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9192. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9193. if((access(fnametemp,F_OK))!=-1)
  9194. {
  9195. strcpy(chargingProfiles[i], fnametemp);
  9196. i = i + 1;
  9197. }
  9198. }
  9199. //Check TxProfile_%d.json
  9200. for(int j=1; j <= gunTotalNumber; j++)
  9201. {
  9202. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9203. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9204. if((access(fnametemp,F_OK))!=-1)
  9205. {
  9206. strcpy(chargingProfiles[i], fnametemp);
  9207. i = i + 1;
  9208. }
  9209. }
  9210. ChargeProfileCount = i;
  9211. }// End connectorIsNULL is TRUE
  9212. if(ChargeProfileCount == 0)
  9213. {
  9214. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9215. goto end;
  9216. }
  9217. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9218. {
  9219. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9220. goto end;
  9221. }
  9222. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9223. {
  9224. memset(str, 0, ARRAY_SIZE(str));
  9225. // clear temp file
  9226. sprintf(str,"rm -f %s",temp);
  9227. system(str);
  9228. for(int k=0; k < ChargeProfileCount; k++)
  9229. {
  9230. memset(str, 0, ARRAY_SIZE(str));
  9231. //clear file in C
  9232. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9233. system(str);
  9234. }
  9235. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9236. goto end;
  9237. }
  9238. else if(connectorIsNULL == TRUE)
  9239. {
  9240. for(int k=0; k < ChargeProfileCount; k++)
  9241. {
  9242. fptr1 = fopen(chargingProfiles[k], "r");
  9243. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9244. //Check Charging Profile Count
  9245. while(fscanf(fptr1, "%s", word) != EOF)
  9246. {
  9247. //DEBUG_INFO("word=%s\n",word);
  9248. if(strstr(word, "chargingProfileId")!= NULL)
  9249. {
  9250. //DEBUG_INFO("test chargingProfileId \n");
  9251. n_chargingProfile = n_chargingProfile + 1;
  9252. //DEBUG_INFO("chargingProfileId Found\n");
  9253. }
  9254. }
  9255. rewind(fptr1);
  9256. //search Charging Profile Element
  9257. //int i= 0;
  9258. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9259. {
  9260. json_object *tmpProfilee;
  9261. tmpProfilee = json_tokener_parse(sLineWord);
  9262. if(!is_error(tmpProfilee))
  9263. {
  9264. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9265. {
  9266. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9267. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9268. }
  9269. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9270. {
  9271. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9272. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9273. }
  9274. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9275. {
  9276. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9277. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9278. }
  9279. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9280. {
  9281. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9282. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9283. }
  9284. }
  9285. json_object_put(tmpProfilee);
  9286. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9287. {
  9288. //------- not write to fptr2-------//
  9289. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9290. //clearflag = TRUE;
  9291. }
  9292. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9293. {
  9294. //------- not write to fptr2-------//
  9295. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9296. }
  9297. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9298. {
  9299. //------- not write to fptr2-------//
  9300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9301. }
  9302. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9303. {
  9304. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9305. }
  9306. else
  9307. {
  9308. fprintf(fptr2, sLineWord);//writing data into file
  9309. }
  9310. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9311. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9312. if(clearflag == TRUE)
  9313. {
  9314. fclose(fptr1);
  9315. fclose(fptr2);
  9316. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9317. system(str);
  9318. // clear temp file
  9319. sprintf(str,"rm -f %s",temp);
  9320. system(str);
  9321. }
  9322. else
  9323. {
  9324. fclose(fptr1);
  9325. fclose(fptr2);
  9326. memset(str, 0, ARRAY_SIZE(str));
  9327. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9328. system(str);
  9329. resultRename = rename(temp, chargingProfiles[k]);
  9330. if(resultRename == 0)
  9331. {
  9332. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9333. }
  9334. else
  9335. {
  9336. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9337. }
  9338. if(comfirmstr[0]== 0)
  9339. {
  9340. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9341. }
  9342. //Check chargingProfile is empty file
  9343. /*------ Read the file ----------------*/
  9344. fptr1=fopen(chargingProfiles[k],"r");
  9345. ch=fgetc(fptr1);
  9346. rewind(fptr1);
  9347. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9348. if(ch!=EOF)
  9349. {
  9350. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9351. {
  9352. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9353. if(sLineWord[0]=='\0')
  9354. {
  9355. isEmptyFile = TRUE;
  9356. break;
  9357. }
  9358. else
  9359. {
  9360. isEmptyFile = FALSE;
  9361. break;
  9362. }
  9363. }
  9364. }
  9365. else
  9366. isEmptyFile = TRUE;
  9367. fclose(fptr1);
  9368. if(isEmptyFile == TRUE)
  9369. {
  9370. memset(str, 0, ARRAY_SIZE(str));
  9371. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9372. system(str);
  9373. }
  9374. }
  9375. }// End of while(int k=0; k < ChargePointCount; k++)
  9376. }
  9377. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9378. {
  9379. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9380. for(int k=0; k < ChargeProfileCount; k++)
  9381. {
  9382. fptr1 = fopen(chargingProfiles[k], "r");
  9383. fptr2 = fopen(temp, "w+");
  9384. //Check Charging Profile Count
  9385. while(fscanf(fptr1, "%s", word) != EOF)
  9386. {
  9387. //DEBUG_INFO("word=%s\n",word);
  9388. if(strstr(word, "chargingProfileId")!= NULL)
  9389. {
  9390. n_chargingProfile = n_chargingProfile + 1;
  9391. }
  9392. }
  9393. rewind(fptr1);
  9394. //search Charging Profile Element
  9395. //int i= 0;
  9396. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9397. {
  9398. json_object *tmpProfilee;
  9399. tmpProfilee = json_tokener_parse(sLineWord);
  9400. if(!is_error(tmpProfilee))
  9401. {
  9402. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9403. {
  9404. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9405. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9406. }
  9407. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9408. {
  9409. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9410. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9411. }
  9412. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9413. {
  9414. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9415. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9416. }
  9417. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9418. {
  9419. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9420. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9421. }
  9422. }
  9423. json_object_put(tmpProfilee);
  9424. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9425. {
  9426. //------- not write to fptr2-------//
  9427. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9428. //clearflag = TRUE;
  9429. }
  9430. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9431. {
  9432. //------- not write to fptr2-------//
  9433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9434. }
  9435. else if(stackLevelIsNULL == TRUE)
  9436. {
  9437. //Clear Whole File
  9438. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9439. clearflag = TRUE;
  9440. break;
  9441. }
  9442. else
  9443. {
  9444. fprintf(fptr2, sLineWord);//writing data into file
  9445. }
  9446. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9447. }
  9448. if(clearflag == TRUE)
  9449. {
  9450. fclose(fptr1);
  9451. fclose(fptr2);
  9452. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9453. system(str);
  9454. // clear temp file
  9455. sprintf(str,"rm -f %s",temp);
  9456. system(str);
  9457. }
  9458. else
  9459. {
  9460. fclose(fptr1);
  9461. fclose(fptr2);
  9462. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9463. system(str);
  9464. resultRename = rename(temp, chargingProfiles[k]);
  9465. if(resultRename == 0)
  9466. {
  9467. DEBUG_INFO("File ChargingProfile renamed successfully");
  9468. }
  9469. else
  9470. {
  9471. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9472. }
  9473. if(comfirmstr[0]== 0)
  9474. {
  9475. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9476. }
  9477. //Check chargingProfile is empty file
  9478. /*------ Read the file ----------------*/
  9479. fptr1=fopen(chargingProfiles[k],"r");
  9480. ch=fgetc(fptr1);
  9481. rewind(fptr1);
  9482. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9483. if(ch!=EOF)
  9484. {
  9485. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9486. {
  9487. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9488. if(sLineWord[0]=='\0')
  9489. {
  9490. isEmptyFile = TRUE;
  9491. break;
  9492. }
  9493. else
  9494. {
  9495. isEmptyFile = FALSE;
  9496. break;
  9497. }
  9498. }
  9499. }
  9500. else
  9501. isEmptyFile = TRUE;
  9502. fclose(fptr1);
  9503. if(isEmptyFile == TRUE)
  9504. {
  9505. memset(str, 0, ARRAY_SIZE(str));
  9506. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9507. system(str);
  9508. }
  9509. /*------- End of reading ---------------*/
  9510. }
  9511. } // while(int k=0; k < ChargeProfileCount; k++)
  9512. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9513. end:
  9514. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9515. {
  9516. if(connectorIdInt == 0)
  9517. {
  9518. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9519. {
  9520. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9521. }
  9522. }
  9523. else
  9524. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9525. }
  9526. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9527. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9528. return result;
  9529. }
  9530. void createFirmwareVersionByDataTransfer(void)
  9531. {
  9532. json_object *FirmwareDataTransfer = json_object_new_object();
  9533. // AC & DC model
  9534. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9535. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9536. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9537. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9538. // DC model
  9539. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9540. {
  9541. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9542. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9543. (gunType[3] != GUN_TYPE_UNKNOWN))
  9544. {
  9545. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9546. }
  9547. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9548. {
  9549. // DS DM DW
  9550. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9551. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9552. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9553. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9554. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9555. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9556. }
  9557. else
  9558. {
  9559. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9560. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9561. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9562. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9563. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9564. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9565. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9566. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9567. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9568. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9569. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9570. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9571. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9573. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9575. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9577. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9579. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9581. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9583. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9584. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9585. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9586. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9587. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9588. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9589. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9590. }
  9591. }
  9592. // 4G model
  9593. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9594. {
  9595. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9596. }
  9597. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9598. json_object_put(FirmwareDataTransfer);
  9599. }
  9600. int handleDataTransferRequest(char *uuid, char *payload)
  9601. {
  9602. mtrace();
  9603. json_object *response = json_object_new_object();
  9604. int result = FAIL;
  9605. char tempvendorId[255]={0};
  9606. char tempmessageId[50]={0};
  9607. char tempdata[1024]={0};
  9608. char message[2048]={0};
  9609. DEBUG_INFO("handleDataTransferRequest...\n");
  9610. if((uuid != NULL) && (payload != NULL))
  9611. {
  9612. json_object *DataTransfer;
  9613. DataTransfer = json_tokener_parse(payload);
  9614. if(!is_error(DataTransfer))
  9615. {
  9616. // Required data
  9617. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9618. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9619. // Optional data
  9620. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9621. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9622. if(json_object_object_get(DataTransfer, "data") != NULL)
  9623. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9624. result = PASS;
  9625. }
  9626. json_object_put(DataTransfer);
  9627. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9628. {
  9629. // Send all moudle firmware version on EVSE
  9630. createFirmwareVersionByDataTransfer();
  9631. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9632. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9633. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9634. json_object_put(response);
  9635. }
  9636. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9637. {
  9638. system("/usr/bin/run_tmate_restart.sh &");
  9639. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9640. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9641. json_object_put(response);
  9642. }
  9643. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9644. {
  9645. json_object *data;
  9646. data = json_tokener_parse(tempdata);
  9647. if(!is_error(data))
  9648. {
  9649. 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))
  9650. {
  9651. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9652. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9653. if(json_object_object_get(data, "SOC") != NULL)
  9654. {
  9655. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9656. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9657. }
  9658. if(json_object_object_get(data, "Energy") != NULL)
  9659. {
  9660. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9661. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9662. }
  9663. if(json_object_object_get(data, "Duration") != NULL)
  9664. {
  9665. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9666. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9667. }
  9668. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9669. }
  9670. else
  9671. {
  9672. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9673. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9674. }
  9675. }
  9676. else
  9677. {
  9678. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9679. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9680. }
  9681. json_object_put(data);
  9682. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9683. json_object_put(response);
  9684. }
  9685. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9686. {
  9687. json_object *data;
  9688. data = json_tokener_parse(tempdata);
  9689. if(!is_error(data))
  9690. {
  9691. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9692. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9693. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9694. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9695. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9696. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9697. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9698. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9699. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9700. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9701. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9702. }
  9703. else
  9704. {
  9705. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9706. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9707. }
  9708. json_object_put(data);
  9709. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9710. json_object_put(response);
  9711. }
  9712. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9713. {
  9714. json_object *data;
  9715. data = json_tokener_parse(tempdata);
  9716. if(!is_error(data))
  9717. {
  9718. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9720. if(json_object_object_get(data, "idToken") != NULL)
  9721. {
  9722. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9723. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9724. }
  9725. else
  9726. {
  9727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9728. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9729. }
  9730. if(json_object_object_get(data, "price") != NULL) //v1.0
  9731. {
  9732. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9733. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9734. }
  9735. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9736. {
  9737. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9738. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9739. }
  9740. else
  9741. {
  9742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9743. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9744. }
  9745. }
  9746. else
  9747. {
  9748. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9749. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9750. }
  9751. json_object_put(data);
  9752. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9753. json_object_put(response);
  9754. }
  9755. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9756. {
  9757. json_object *data;
  9758. data = json_tokener_parse(tempdata);
  9759. if(!is_error(data))
  9760. {
  9761. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9762. if(json_object_object_get(data, "txId") != NULL)
  9763. {
  9764. // California pricing V1.0
  9765. DEBUG_INFO("California pricing V1.0\n");
  9766. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9767. sprintf((char*)dmsVersion, "1.0");
  9768. for(int idx = 0;idx<gunTotalNumber;idx++)
  9769. {
  9770. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9771. {
  9772. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9773. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9774. if(json_object_object_get(data, "description") != NULL)
  9775. {
  9776. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9777. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9778. }
  9779. else
  9780. {
  9781. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9782. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9783. }
  9784. }
  9785. }
  9786. }
  9787. else if(json_object_object_get(data, "transactionId") != NULL)
  9788. {
  9789. // California pricing V2.0
  9790. DEBUG_INFO("California pricing V2.0\n");
  9791. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9792. sprintf((char*)dmsVersion, "2.0");
  9793. for(int idx=0;idx<gunTotalNumber;idx++)
  9794. {
  9795. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9796. {
  9797. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9798. if(json_object_object_get(data, "timestamp") != NULL)
  9799. {
  9800. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9801. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9802. }
  9803. else
  9804. {
  9805. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9806. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9807. }
  9808. if(json_object_object_get(data, "meterValue") != NULL)
  9809. {
  9810. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9811. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9812. }
  9813. else
  9814. {
  9815. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9816. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9817. }
  9818. if(json_object_object_get(data, "cost") != NULL)
  9819. {
  9820. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9821. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9822. }
  9823. else
  9824. {
  9825. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9826. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9827. }
  9828. if(json_object_object_get(data, "state") != NULL)
  9829. {
  9830. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9831. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9832. }
  9833. else
  9834. {
  9835. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9836. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9837. }
  9838. if(json_object_object_get(data, "chargingPrice") != NULL)
  9839. {
  9840. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9841. {
  9842. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9843. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9844. }
  9845. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9846. {
  9847. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9848. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9849. }
  9850. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9851. {
  9852. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9853. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9854. }
  9855. }
  9856. else
  9857. {
  9858. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9859. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9860. }
  9861. if(json_object_object_get(data, "idlePrice") != NULL)
  9862. {
  9863. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9864. {
  9865. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9866. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9867. }
  9868. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9869. {
  9870. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9871. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9872. }
  9873. }
  9874. if(json_object_object_get(data, "nextPeriod") != NULL)
  9875. {
  9876. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9877. {
  9878. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9879. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9880. }
  9881. else
  9882. {
  9883. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9884. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9885. }
  9886. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9887. {
  9888. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9889. {
  9890. 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")));
  9891. 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"));
  9892. }
  9893. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9894. {
  9895. 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")));
  9896. 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"));
  9897. }
  9898. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9899. {
  9900. 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")));
  9901. 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"));
  9902. }
  9903. }
  9904. else
  9905. {
  9906. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9907. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9908. }
  9909. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9910. {
  9911. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9912. {
  9913. 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")));
  9914. 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"));
  9915. }
  9916. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9917. {
  9918. 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")));
  9919. 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"));
  9920. }
  9921. }
  9922. }
  9923. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9924. {
  9925. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9926. {
  9927. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9928. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9929. }
  9930. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9931. {
  9932. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9933. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9934. }
  9935. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9936. {
  9937. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9938. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9939. }
  9940. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9941. {
  9942. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9943. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9944. }
  9945. }
  9946. }
  9947. }
  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("txId or transactionId not found."));
  9953. }
  9954. }
  9955. else
  9956. {
  9957. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9958. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9959. }
  9960. json_object_put(data);
  9961. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9962. json_object_put(response);
  9963. }
  9964. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9965. {
  9966. json_object *data;
  9967. data = json_tokener_parse(tempdata);
  9968. if(!is_error(data))
  9969. {
  9970. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9971. if(json_object_object_get(data, "txId") != NULL)
  9972. {
  9973. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9974. for(int idx = 0;idx<gunTotalNumber;idx++)
  9975. {
  9976. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9977. {
  9978. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9979. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9980. if(json_object_object_get(data, "description") != NULL)
  9981. {
  9982. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9983. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9984. }
  9985. else
  9986. {
  9987. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9988. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9989. }
  9990. }
  9991. }
  9992. }
  9993. else if(json_object_object_get(data, "transactionId") != NULL)
  9994. {
  9995. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9996. for(int idx = 0;idx<gunTotalNumber;idx++)
  9997. {
  9998. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9999. {
  10000. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10001. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10002. if(json_object_object_get(data, "cost") != NULL)
  10003. {
  10004. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10005. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10006. }
  10007. else
  10008. {
  10009. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10010. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10011. }
  10012. if(json_object_object_get(data, "priceText") != NULL)
  10013. {
  10014. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10015. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10016. }
  10017. else
  10018. {
  10019. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10020. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10021. }
  10022. if(json_object_object_get(data, "qrCodeText") != NULL)
  10023. {
  10024. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10025. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10026. }
  10027. }
  10028. }
  10029. }
  10030. else
  10031. {
  10032. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10033. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10034. }
  10035. }
  10036. else
  10037. {
  10038. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10039. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10040. }
  10041. json_object_put(data);
  10042. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10043. json_object_put(response);
  10044. }
  10045. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10046. {
  10047. json_object *data;
  10048. data = json_tokener_parse(tempdata);
  10049. if(!is_error(data))
  10050. {
  10051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10052. if(json_object_object_get(data, "Content_Type") != NULL)
  10053. {
  10054. 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))
  10055. {
  10056. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10057. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10058. {
  10059. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10060. }
  10061. }
  10062. else
  10063. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10064. }
  10065. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10066. }
  10067. else
  10068. {
  10069. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10070. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10071. }
  10072. json_object_put(data);
  10073. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10074. json_object_put(response);
  10075. }
  10076. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10077. {
  10078. json_object *data;
  10079. data = json_tokener_parse(tempdata);
  10080. if(!is_error(data))
  10081. {
  10082. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10083. if(json_object_object_get(data, "ConnectorId") != NULL)
  10084. {
  10085. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10086. }
  10087. if(json_object_object_get(data, "SerialNo") != NULL)
  10088. {
  10089. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10090. }
  10091. if(json_object_object_get(data, "Page_Index") != NULL)
  10092. {
  10093. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10094. }
  10095. if(json_object_object_get(data, "Duration") != NULL)
  10096. {
  10097. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10098. }
  10099. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10100. }
  10101. else
  10102. {
  10103. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10104. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10105. }
  10106. json_object_put(data);
  10107. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10108. json_object_put(response);
  10109. }
  10110. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10111. {
  10112. json_object *data;
  10113. data = json_tokener_parse(tempdata);
  10114. if(!is_error(data))
  10115. {
  10116. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10117. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10118. {
  10119. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10120. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10121. else
  10122. {
  10123. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10124. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10125. }
  10126. }
  10127. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10128. {
  10129. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10130. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10131. else
  10132. {
  10133. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10134. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10135. }
  10136. }
  10137. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10138. {
  10139. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10140. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10141. else
  10142. {
  10143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10144. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10145. }
  10146. }
  10147. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10148. {
  10149. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10150. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  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("Configuration content something wrong."));
  10155. }
  10156. }
  10157. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10158. {
  10159. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10160. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10161. else
  10162. {
  10163. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10164. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10165. }
  10166. }
  10167. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10168. {
  10169. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10170. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10171. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10172. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10173. else
  10174. {
  10175. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10176. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10177. }
  10178. }
  10179. if(json_object_object_get(data, "isAuthentication") != NULL)
  10180. {
  10181. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10182. {
  10183. case 0:
  10184. case 1:
  10185. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10186. break;
  10187. default:
  10188. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10189. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10190. break;
  10191. }
  10192. }
  10193. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10194. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10195. }
  10196. else
  10197. {
  10198. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10199. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10200. }
  10201. json_object_put(data);
  10202. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10203. json_object_put(response);
  10204. }
  10205. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10206. {
  10207. json_object *data;
  10208. data = json_tokener_parse(tempdata);
  10209. if(!is_error(data))
  10210. {
  10211. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10212. {
  10213. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10214. {
  10215. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10216. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10217. }
  10218. else
  10219. {
  10220. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10221. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10222. }
  10223. }
  10224. else
  10225. {
  10226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10227. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10228. }
  10229. }
  10230. else
  10231. {
  10232. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10233. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10234. }
  10235. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10236. json_object_put(response);
  10237. }
  10238. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10239. {
  10240. json_object *data;
  10241. data = json_tokener_parse(tempdata);
  10242. if(!is_error(data))
  10243. {
  10244. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10245. if(json_object_object_get(data, "stationName") != NULL)
  10246. {
  10247. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10248. }
  10249. else
  10250. {
  10251. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10252. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10253. }
  10254. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10255. {
  10256. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10257. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10258. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10259. }
  10260. }
  10261. else
  10262. {
  10263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10264. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10265. }
  10266. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10267. json_object_put(response);
  10268. }
  10269. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10270. {
  10271. json_object *data;
  10272. data = json_tokener_parse(tempdata);
  10273. if(!is_error(data))
  10274. {
  10275. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10276. if(json_object_object_get(data, "weatherId") != NULL)
  10277. {
  10278. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10279. }
  10280. else
  10281. {
  10282. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10283. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10284. }
  10285. if(json_object_object_get(data, "Temperature") != NULL)
  10286. {
  10287. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10288. }
  10289. else
  10290. {
  10291. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10292. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10293. }
  10294. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10295. {
  10296. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10297. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10298. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10299. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10300. );
  10301. }
  10302. }
  10303. else
  10304. {
  10305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10306. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10307. }
  10308. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10309. json_object_put(response);
  10310. }
  10311. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10312. {
  10313. json_object *data;
  10314. data = json_tokener_parse(tempdata);
  10315. if(!is_error(data))
  10316. {
  10317. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10318. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10319. {
  10320. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10321. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10322. }
  10323. else
  10324. {
  10325. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10326. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10327. }
  10328. }
  10329. else
  10330. {
  10331. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10332. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10333. }
  10334. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10335. json_object_put(response);
  10336. }
  10337. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10338. {
  10339. json_object *data;
  10340. data = json_tokener_parse(tempdata);
  10341. if(!is_error(data))
  10342. {
  10343. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10344. {
  10345. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10346. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10347. if(gun_index < gunTotalNumber)
  10348. {
  10349. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10350. {
  10351. json_object *responsedata = json_object_new_object();
  10352. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10353. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10354. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10355. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10356. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10357. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10358. }
  10359. else
  10360. {
  10361. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10362. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10363. }
  10364. }
  10365. else
  10366. {
  10367. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10368. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10369. }
  10370. }
  10371. else
  10372. {
  10373. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10374. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10375. }
  10376. }
  10377. else
  10378. {
  10379. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10380. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10381. }
  10382. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10383. json_object_put(response);
  10384. }
  10385. else
  10386. {
  10387. // Can not find valid message id
  10388. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10389. }
  10390. }
  10391. else
  10392. {
  10393. // Payload is null
  10394. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10395. }
  10396. LWS_Send(message);
  10397. return result;
  10398. }
  10399. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10400. {
  10401. mtrace();
  10402. int result = FAIL;
  10403. int connectorIdInt, durationInt;
  10404. char chargingRateUnitStr[4]={0};
  10405. char comfirmstr[20];
  10406. int confirmPeriods = 0;
  10407. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10408. json_object *GetCompositeSchedule;
  10409. GetCompositeSchedule = json_tokener_parse(payload);
  10410. if(!is_error(GetCompositeSchedule))
  10411. {
  10412. // Required data
  10413. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10414. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10415. else
  10416. connectorIdInt = -1;
  10417. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10418. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10419. else
  10420. durationInt = 86400;
  10421. // Optional data
  10422. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10423. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10424. }
  10425. json_object_put(GetCompositeSchedule);
  10426. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10427. if((connectorIdInt == 0) ||
  10428. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10429. {
  10430. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10431. struct StructChargingProfile tmpProfile[1];
  10432. if(strstr(chargingRateUnitStr, "W") != NULL)
  10433. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10434. else
  10435. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10436. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10437. {
  10438. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10439. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10440. }
  10441. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10442. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10443. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10444. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10445. {
  10446. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10447. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10448. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10449. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10450. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10451. {
  10452. confirmPeriods = idx;
  10453. break;
  10454. }
  10455. }
  10456. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10457. {
  10458. confirmPeriods += 1;
  10459. }
  10460. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10461. }
  10462. else
  10463. {
  10464. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10465. }
  10466. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10467. return result;
  10468. }
  10469. int handleGetConfigurationRequest(char *uuid, char *payload)
  10470. {
  10471. mtrace();
  10472. int result = FAIL;
  10473. int MaxKeySupported = 0;
  10474. int n_keys = 0;
  10475. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10476. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10477. json_object *GetConfiguration;
  10478. GetConfiguration = json_tokener_parse(payload);
  10479. if(!is_error(GetConfiguration))
  10480. {
  10481. // Optional data
  10482. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10483. {
  10484. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10485. {
  10486. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10487. n_keys = idx + 1;
  10488. }
  10489. }
  10490. }
  10491. json_object_put(GetConfiguration);
  10492. UnknownKeynum = 0;
  10493. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10494. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10495. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10496. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10497. if(n_keys != 0)
  10498. {
  10499. for(int i=0;i<n_keys;i++)
  10500. {
  10501. getKeyValue(requestKey[i]);
  10502. }
  10503. }
  10504. else
  10505. {
  10506. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10507. getKeyValue("");
  10508. }
  10509. processUnkownKey();
  10510. sendGetConfigurationConfirmation(uuid);
  10511. return result;
  10512. }
  10513. static char fnamePlusPath[100]={0};
  10514. static char fnamePWithNoPath[60]={0};
  10515. void checkUploadLog(void)
  10516. {
  10517. FILE *fp;
  10518. /* Open the command for reading. */
  10519. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10520. if (fp == NULL) {
  10521. DEBUG_WARN("Failed to run command\n" );
  10522. exit(1);
  10523. }
  10524. int ftppathlen = 0;
  10525. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10526. int i = 0;
  10527. /* Read the output a line at a time - output it. */
  10528. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10529. if(i==0)
  10530. {
  10531. ftppathlen = strlen(fnamePlusPath);
  10532. DEBUG_INFO("%s\n", fnamePlusPath);
  10533. fnamePlusPath[ftppathlen]='\0';
  10534. break;
  10535. }
  10536. i= i+1;
  10537. }
  10538. /* close */
  10539. pclose(fp);
  10540. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10541. {
  10542. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10543. {
  10544. fnamePlusPath[k]='\0';
  10545. }
  10546. }
  10547. i=1;
  10548. //char fname[60]={0};
  10549. while(i < ftppathlen)
  10550. {
  10551. int len=ftppathlen-i;
  10552. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10553. {
  10554. DEBUG_INFO("compare '/' all right\n");
  10555. break;
  10556. }
  10557. i=i+1;
  10558. }
  10559. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10560. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10561. fnamePWithNoPath[i+1] = '\0';
  10562. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10563. {
  10564. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10565. {
  10566. fnamePWithNoPath[j]='\0';
  10567. }
  10568. }
  10569. FILE* fp1 = fopen(fnamePlusPath, "r");
  10570. if (fp1)
  10571. {
  10572. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10573. // file exists
  10574. fclose(fp1);
  10575. }
  10576. else
  10577. {
  10578. // file doesn't exist
  10579. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10580. }
  10581. }
  10582. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10583. {
  10584. mtrace();
  10585. int result = FAIL;
  10586. time_t CurrentTime;
  10587. struct tm *tm;
  10588. pthread_t th_Status;
  10589. CurrentTime = time(NULL);
  10590. tm = localtime(&CurrentTime);
  10591. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10592. 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);
  10593. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10594. if(!interLock.isGetDiagnosticGoing)
  10595. {
  10596. interLock.isGetDiagnosticGoing = 1;
  10597. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10598. sleep(1);
  10599. }
  10600. else
  10601. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10602. return result;
  10603. }
  10604. void* GetDiagnosticsProcess(void* data)
  10605. {
  10606. pthread_detach(pthread_self());
  10607. mtrace();
  10608. int retriesInt=0, retryIntervalInt=0;
  10609. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10610. 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};
  10611. int port=0;
  10612. int isSuccess = FALSE;
  10613. char cmdBuf[2048];
  10614. struct tm *tmNow;
  10615. time_t CurrentTime;
  10616. struct tm tmStart;
  10617. struct tm tmStop;
  10618. CurrentTime = time(NULL);
  10619. tmNow=localtime(&CurrentTime);
  10620. uint16_t targetYear, targetMonth;
  10621. json_object *GetDiagnostics;
  10622. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10623. GetDiagnostics = json_tokener_parse(data);
  10624. if(!is_error(GetDiagnostics))
  10625. {
  10626. // Required data
  10627. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10628. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10629. // Optional data
  10630. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10631. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10632. else
  10633. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10634. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10635. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10636. else
  10637. retryIntervalInt = 30;
  10638. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10639. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10640. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10641. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10642. }
  10643. json_object_put(GetDiagnostics);
  10644. // Pack log to compress file
  10645. 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) &&
  10646. (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))
  10647. {
  10648. // Pack system log
  10649. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10650. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10651. targetYear = tmStart.tm_year;
  10652. targetMonth = tmStart.tm_mon;
  10653. do
  10654. {
  10655. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10656. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10657. if(targetMonth+1>=13)
  10658. {
  10659. targetYear += 1;
  10660. targetMonth = 1;
  10661. }
  10662. else
  10663. {
  10664. targetMonth += 1;
  10665. }
  10666. }while((targetYear < (tmNow->tm_year+1900)) ||
  10667. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10668. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10669. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10670. system(cmdBuf);
  10671. // Pack charging & event log
  10672. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10673. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10674. targetYear = tmStart.tm_year;
  10675. targetMonth = tmStart.tm_mon;
  10676. do
  10677. {
  10678. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10679. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10680. if(targetMonth+1>=13)
  10681. {
  10682. targetYear += 1;
  10683. targetMonth = 1;
  10684. }
  10685. else
  10686. {
  10687. targetMonth += 1;
  10688. }
  10689. }while((targetYear < (tmNow->tm_year+1900)) ||
  10690. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10691. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10692. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10693. system(cmdBuf);
  10694. // Combine log file
  10695. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10696. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10697. }
  10698. else
  10699. {
  10700. system("exec /root/logPackTools 'log' 6");
  10701. }
  10702. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10703. system(cmdBuf);
  10704. checkUploadLog();
  10705. //****************location*******************/
  10706. if(strcmp(locationstr,"")==0)
  10707. {
  10708. DEBUG_INFO("location is <Empty>!\n");
  10709. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10710. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10711. goto end;
  10712. }
  10713. memset(protocol, 0, ARRAY_SIZE(protocol));
  10714. memset(user, 0, ARRAY_SIZE(user) );
  10715. memset(password, 0, ARRAY_SIZE(password));
  10716. memset(host, 0, ARRAY_SIZE(host));
  10717. memset(path, 0, ARRAY_SIZE(path));
  10718. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10719. memset(host1, 0, ARRAY_SIZE(host1));
  10720. memset(path1, 0, ARRAY_SIZE(path1));
  10721. /*location: ftp://user:password@host:port/path*/
  10722. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10723. if((access(fnamePlusPath,F_OK))!=-1)
  10724. {
  10725. DEBUG_INFO("fnamePlusPath exist.\n");
  10726. }
  10727. else
  10728. {
  10729. DEBUG_INFO("fnamePlusPath not exist!\n");
  10730. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10731. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10732. goto end;
  10733. }
  10734. if(strchr(locationstr,'@')==NULL)
  10735. {
  10736. sscanf(locationstr,
  10737. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10738. protocol, host, &port, path);
  10739. strcpy(user,"anonymous");
  10740. strcpy(password,"");
  10741. }
  10742. else
  10743. {
  10744. //DEBUG_INFO("pch=%s\n", pch);
  10745. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10746. protocol, user, password, host, &port, path);
  10747. }
  10748. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10749. {
  10750. DEBUG_INFO("protocol is not ftp/http ! \n");
  10751. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10752. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10753. goto end;
  10754. }
  10755. if(strncmp(locationstr,"http", 4) == 0)
  10756. {
  10757. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10758. sprintf(ftppath,"/%s", path);
  10759. do
  10760. {
  10761. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10762. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10763. sleep(3);
  10764. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10765. if(!isSuccess)
  10766. {
  10767. DEBUG_INFO("Diagnostics fail.\n");
  10768. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10769. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10770. sleep(retryIntervalInt);
  10771. }
  10772. else
  10773. {
  10774. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10775. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10776. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10777. }
  10778. retriesInt--;
  10779. }while((isSuccess == 0)&&(retriesInt >= 0));
  10780. }
  10781. else
  10782. {
  10783. sscanf(host,"%[^/]%s",host1, path1);
  10784. if(strlen(path) > 0)
  10785. sprintf(ftppath,"/%s", path);
  10786. else
  10787. sprintf(ftppath,"/%s", path1);
  10788. int ftppathlen=strlen(ftppath);
  10789. int i=1;
  10790. char filenametemp[50];
  10791. while(i < ftppathlen)
  10792. {
  10793. int len=ftppathlen-i;
  10794. if(ftppath[len]== 47) // '/' ascll code: 47
  10795. {
  10796. DEBUG_INFO("find '/' all right\n");
  10797. break;
  10798. }
  10799. i=i+1;
  10800. }
  10801. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10802. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10803. filenametemp[i+1] = 0;
  10804. if(port == 0)
  10805. port = 21;
  10806. do
  10807. {
  10808. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10809. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10810. sleep(3);
  10811. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10812. if(!isSuccess)
  10813. {
  10814. DEBUG_INFO("Diagnostics fail.\n");
  10815. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10816. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10817. sleep(retryIntervalInt);
  10818. }
  10819. else
  10820. {
  10821. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10822. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10823. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10824. }
  10825. retriesInt--;
  10826. }while((!isSuccess)&&(retriesInt >= 0));
  10827. }
  10828. end:
  10829. system("rm -f /mnt/*");
  10830. sleep(5);
  10831. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10832. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10833. interLock.isGetDiagnosticGoing = 0;
  10834. pthread_exit(NULL);
  10835. }
  10836. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10837. {
  10838. mtrace();
  10839. int result = FAIL;
  10840. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10841. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10842. {
  10843. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10844. locallistVersion = -1;
  10845. }
  10846. else
  10847. {
  10848. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10849. locallistVersion = 0;
  10850. OCPP_getListVerion();
  10851. }
  10852. //from db.OCPP_getListVerion
  10853. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10854. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10855. sendGetLocalListVersionConfirmation(uuid,"");
  10856. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10857. return result;
  10858. }
  10859. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10860. {
  10861. mtrace();
  10862. int result = FAIL;
  10863. int connectorIdInt=-1;
  10864. int tempIndex = 0;
  10865. int connectorIdIsNULL, chargingProfileIsNULL;
  10866. char comfirmstr[20]={0};
  10867. char cmdBuf[512];
  10868. json_object *RemoteStartTransaction;
  10869. FILE *fp;
  10870. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10871. if(server_pending == TRUE)
  10872. {
  10873. return 0;
  10874. }
  10875. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10876. RemoteStartTransaction = json_tokener_parse(payload);
  10877. if(!is_error(RemoteStartTransaction))
  10878. {
  10879. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10880. {
  10881. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10882. }
  10883. else
  10884. {
  10885. connectorIdIsNULL = TRUE;
  10886. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10887. {
  10888. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10889. {
  10890. connectorIdIsNULL = FALSE;
  10891. connectorIdInt = (gun_index+1);
  10892. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10893. break;
  10894. }
  10895. }
  10896. }
  10897. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10898. {
  10899. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10900. // Required data
  10901. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10902. // Optional data
  10903. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10904. {
  10905. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10906. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10907. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10908. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10909. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10910. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10911. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10912. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10913. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10914. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10915. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10916. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10917. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10918. {
  10919. 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")));
  10920. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10921. 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"));
  10922. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10923. 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"));
  10924. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10925. 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")));
  10926. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10927. {
  10928. 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++)
  10929. {
  10930. 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"));
  10931. 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"));
  10932. 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)
  10933. 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"));
  10934. }
  10935. }
  10936. }
  10937. }
  10938. else
  10939. {
  10940. chargingProfileIsNULL = TRUE;
  10941. }
  10942. }
  10943. }
  10944. else
  10945. {
  10946. connectorIdIsNULL = TRUE;
  10947. }
  10948. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10949. {
  10950. DEBUG_WARN("Connector id is NULL\n.");
  10951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10952. goto end;
  10953. }
  10954. /*
  10955. enum _SYSTEM_STATUS
  10956. {
  10957. S_BOOTING = 0,
  10958. S_IDLE, = 1
  10959. S_AUTHORIZING, = 2
  10960. S_REASSIGN_CHECK, = 3
  10961. S_REASSIGN, = 4
  10962. S_PRECHARGE, = 5
  10963. S_PREPARING_FOR_EV, = 6
  10964. S_PREPARING_FOR_EVSE, = 7
  10965. S_CHARGING, = 8
  10966. S_TERMINATING, = 9
  10967. S_COMPLETE, = 10
  10968. S_ALARM, = 11
  10969. S_FAULT = 12
  10970. }
  10971. */
  10972. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10973. {
  10974. //check Transaction active
  10975. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10976. {
  10977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10978. {
  10979. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10980. }
  10981. else
  10982. {
  10983. tempIndex = connectorIdInt -1;
  10984. }
  10985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10986. {
  10987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10988. {
  10989. 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))
  10990. {
  10991. //Reserved
  10992. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10993. }
  10994. 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))
  10995. {
  10996. //Reserved
  10997. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10999. goto end;
  11000. }
  11001. else
  11002. {
  11003. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11004. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11005. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11006. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11007. {
  11008. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  11009. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11010. goto end;
  11011. }
  11012. }//END FOR ELSE
  11013. }
  11014. }// END FOR CHAdeMO_QUANTITY
  11015. }
  11016. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11017. {
  11018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11019. {
  11020. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11021. }
  11022. else
  11023. {
  11024. tempIndex = connectorIdInt -1;
  11025. }
  11026. for (int index = 0; index < CCS_QUANTITY; index++)
  11027. {
  11028. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11029. {
  11030. 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))
  11031. {
  11032. //Reserved
  11033. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11034. }
  11035. 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))
  11036. {
  11037. //Reserved
  11038. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11039. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11040. goto end;
  11041. }
  11042. else
  11043. {
  11044. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11045. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11046. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11047. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11048. {
  11049. DEBUG_WARN("CCS connector not allow start\n.");
  11050. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11051. goto end;
  11052. }
  11053. }// END FOR ELSE
  11054. }
  11055. }// END FOR CCS_QUANTITY
  11056. }
  11057. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11058. {
  11059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11060. {
  11061. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11062. }
  11063. else
  11064. {
  11065. tempIndex = connectorIdInt -1;
  11066. }
  11067. for (int index = 0; index < GB_QUANTITY; index++)
  11068. {
  11069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11070. {
  11071. 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))
  11072. {
  11073. //Reserved
  11074. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11075. }
  11076. 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))
  11077. {
  11078. //Reserved
  11079. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11081. goto end;
  11082. }
  11083. else
  11084. {
  11085. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11086. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11087. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11088. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11089. {
  11090. DEBUG_WARN("GB connector not allow start\n.");
  11091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11092. goto end;
  11093. }
  11094. }// END FOR ELSE
  11095. }
  11096. } // END FOR GB_QUANTITY
  11097. }
  11098. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11099. {
  11100. tempIndex = connectorIdInt -1;
  11101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11102. {
  11103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11104. {
  11105. 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))
  11106. {
  11107. //Reserved
  11108. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11109. }
  11110. 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))
  11111. {
  11112. //Reserved
  11113. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11115. goto end;
  11116. }
  11117. else
  11118. {
  11119. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11120. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11121. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11122. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11123. {
  11124. DEBUG_WARN("GB connector not allow start\n.");
  11125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11126. goto end;
  11127. }
  11128. }// END FOR ELSE
  11129. }
  11130. } // END FOR GB_QUANTITY
  11131. }
  11132. else
  11133. {
  11134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11135. {
  11136. tempIndex = 2;
  11137. }
  11138. else
  11139. {
  11140. tempIndex = connectorIdInt -1;
  11141. }
  11142. for (int index = 0; index < AC_QUANTITY; index++)
  11143. {
  11144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11145. {
  11146. 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))
  11147. {
  11148. //Reserved
  11149. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11150. }
  11151. 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))
  11152. {
  11153. //Reserved
  11154. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11155. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11156. goto end;
  11157. }
  11158. else
  11159. {
  11160. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11161. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11162. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11163. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11164. {
  11165. DEBUG_WARN("AC connector not allow start\n.");
  11166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11167. goto end;
  11168. }
  11169. }//END FOR ELSE
  11170. }
  11171. }// END FOR AC_QUANTITY
  11172. }
  11173. if(chargingProfileIsNULL == FALSE)
  11174. {
  11175. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11176. {
  11177. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11178. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11179. //memset idTag
  11180. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11181. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11182. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11183. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11184. // Save profile to file
  11185. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11186. system(cmdBuf);
  11187. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11188. fp = fopen(cmdBuf, "w");
  11189. 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));
  11190. fclose(fp);
  11191. }
  11192. else
  11193. {
  11194. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11196. }
  11197. }
  11198. else
  11199. {
  11200. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11201. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11202. //memset idTag
  11203. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11204. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11205. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11206. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11207. }
  11208. }
  11209. else
  11210. {
  11211. DEBUG_WARN("Connector id over\n.");
  11212. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11213. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11214. }
  11215. end:
  11216. json_object_put(RemoteStartTransaction);
  11217. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11218. {
  11219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11220. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11221. }
  11222. //OCPP send RemoteStartConfirmation by first.
  11223. sendRemoteStartConfirmation(uuid, comfirmstr);
  11224. return result;
  11225. }
  11226. int handleRemoteStartRequest(char *uuid, char *payload)
  11227. {
  11228. mtrace();
  11229. int result = PASS;
  11230. int connectorIdInt=-1;
  11231. int tempIndex = 0;
  11232. char comfirmstr[20]={0};
  11233. char cmdBuf[512];
  11234. json_object *RemoteStartTransaction;
  11235. FILE *fp;
  11236. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11237. if(server_pending == TRUE)
  11238. {
  11239. result = FAIL;
  11240. }
  11241. RemoteStartTransaction = json_tokener_parse(payload);
  11242. if(!is_error(RemoteStartTransaction))
  11243. {
  11244. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11245. {
  11246. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11247. }
  11248. else
  11249. {
  11250. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11251. {
  11252. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11253. {
  11254. connectorIdInt = (gun_index+1);
  11255. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11256. break;
  11257. }
  11258. }
  11259. }
  11260. if(connectorIdInt == 0)
  11261. {
  11262. DEBUG_WARN("Connector id shall not equal 0.\n");
  11263. result = FAIL;
  11264. }
  11265. else if(connectorIdInt == -1)
  11266. {
  11267. DEBUG_INFO("Connector id does not specific.\n");
  11268. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11269. {
  11270. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11271. // Required data
  11272. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11273. // Optional data
  11274. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11275. {
  11276. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11277. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11278. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11279. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11280. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11281. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11282. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11283. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11284. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11285. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11286. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11287. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11288. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11289. {
  11290. 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")));
  11291. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11292. 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"));
  11293. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11294. 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"));
  11295. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11296. 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")));
  11297. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11298. {
  11299. 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++)
  11300. {
  11301. 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"));
  11302. 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"));
  11303. 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)
  11304. 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"));
  11305. }
  11306. }
  11307. }
  11308. }
  11309. else
  11310. {
  11311. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11312. }
  11313. }
  11314. }
  11315. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11316. {
  11317. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11318. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11319. // Required data
  11320. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11321. // Optional data
  11322. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11323. {
  11324. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11325. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11326. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11327. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11328. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11329. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11330. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11331. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11332. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11333. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11334. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11335. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11336. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11337. {
  11338. 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")));
  11339. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11340. 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"));
  11341. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11342. 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"));
  11343. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11344. 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")));
  11345. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11346. {
  11347. 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++)
  11348. {
  11349. 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"));
  11350. 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"));
  11351. 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)
  11352. 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"));
  11353. }
  11354. }
  11355. }
  11356. }
  11357. else
  11358. {
  11359. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11360. }
  11361. }
  11362. else
  11363. {
  11364. DEBUG_WARN("Connector id is over maximun value.\n");
  11365. result = FAIL;
  11366. }
  11367. }
  11368. if(result == PASS)
  11369. {
  11370. if(connectorIdInt > 0)
  11371. {
  11372. //check Transaction active
  11373. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11374. {
  11375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11376. {
  11377. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11378. }
  11379. else
  11380. {
  11381. tempIndex = connectorIdInt -1;
  11382. }
  11383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11384. {
  11385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11386. {
  11387. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11388. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11389. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11390. {
  11391. //Reserved
  11392. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11393. }
  11394. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11395. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11396. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11397. {
  11398. //Reserved
  11399. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11400. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11401. goto end;
  11402. }
  11403. else
  11404. {
  11405. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11406. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11407. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11408. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11409. {
  11410. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11411. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11412. goto end;
  11413. }
  11414. }//END FOR ELSE
  11415. }
  11416. }// END FOR CHAdeMO_QUANTITY
  11417. }
  11418. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11419. {
  11420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11421. {
  11422. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11423. }
  11424. else
  11425. {
  11426. tempIndex = connectorIdInt -1;
  11427. }
  11428. for (int index = 0; index < CCS_QUANTITY; index++)
  11429. {
  11430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11431. {
  11432. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11433. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11434. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11435. {
  11436. //Reserved
  11437. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11438. }
  11439. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11440. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11441. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11442. {
  11443. //Reserved
  11444. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11446. goto end;
  11447. }
  11448. else
  11449. {
  11450. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11451. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11452. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11453. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11454. {
  11455. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11456. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11457. goto end;
  11458. }
  11459. }// END FOR ELSE
  11460. }
  11461. }// END FOR CCS_QUANTITY
  11462. }
  11463. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11464. {
  11465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11466. {
  11467. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11468. }
  11469. else
  11470. {
  11471. tempIndex = connectorIdInt -1;
  11472. }
  11473. for (int index = 0; index < GB_QUANTITY; index++)
  11474. {
  11475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11476. {
  11477. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11478. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11479. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11480. {
  11481. //Reserved
  11482. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11483. }
  11484. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11485. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11486. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11487. {
  11488. //Reserved
  11489. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11490. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11491. goto end;
  11492. }
  11493. else
  11494. {
  11495. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11496. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11497. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11498. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11499. {
  11500. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11502. goto end;
  11503. }
  11504. }// END FOR ELSE
  11505. }
  11506. } // END FOR GB_QUANTITY
  11507. }
  11508. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11509. {
  11510. tempIndex = connectorIdInt -1;
  11511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11512. {
  11513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11514. {
  11515. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11516. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11517. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11518. {
  11519. //Reserved
  11520. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11521. }
  11522. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11523. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11524. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11525. {
  11526. //Reserved
  11527. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11529. goto end;
  11530. }
  11531. else
  11532. {
  11533. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11534. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11535. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11536. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11537. {
  11538. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11539. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11540. goto end;
  11541. }
  11542. }// END FOR ELSE
  11543. }
  11544. } // END FOR GB_QUANTITY
  11545. }
  11546. else
  11547. {
  11548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11549. {
  11550. tempIndex = 2;
  11551. }
  11552. else
  11553. {
  11554. tempIndex = connectorIdInt -1;
  11555. }
  11556. for (int index = 0; index < AC_QUANTITY; index++)
  11557. {
  11558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11559. {
  11560. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11561. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11562. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11563. {
  11564. //Reserved
  11565. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11566. }
  11567. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11568. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11569. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11570. {
  11571. //Reserved
  11572. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11573. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11574. goto end;
  11575. }
  11576. else
  11577. {
  11578. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11579. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11580. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11581. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11582. {
  11583. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11584. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11585. goto end;
  11586. }
  11587. }//END FOR ELSE
  11588. }
  11589. }// END FOR AC_QUANTITY
  11590. }
  11591. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11592. {
  11593. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11594. {
  11595. // Save profile to file
  11596. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11597. system(cmdBuf);
  11598. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11599. fp = fopen(cmdBuf, "w");
  11600. 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));
  11601. fclose(fp);
  11602. }
  11603. else
  11604. {
  11605. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11606. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11607. goto end;
  11608. }
  11609. }
  11610. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11611. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11612. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11613. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11614. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11615. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11616. }
  11617. else
  11618. {
  11619. uint8_t isHasIdleConnector = FALSE;
  11620. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11621. {
  11622. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11623. {
  11624. isHasIdleConnector = TRUE;
  11625. break;
  11626. }
  11627. }
  11628. if(isHasIdleConnector == TRUE)
  11629. {
  11630. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11631. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11632. {
  11633. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11634. {
  11635. // Save profile to file
  11636. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11637. system(cmdBuf);
  11638. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11639. fp = fopen(cmdBuf, "w");
  11640. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11641. fclose(fp);
  11642. refreshStartTimer(&clientTime.RemoteStartWait);
  11643. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11644. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11645. }
  11646. else
  11647. {
  11648. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11649. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11650. }
  11651. }
  11652. else
  11653. {
  11654. refreshStartTimer(&clientTime.RemoteStartWait);
  11655. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11656. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11657. }
  11658. }
  11659. else
  11660. {
  11661. DEBUG_INFO("There is not any connector is idle.\n");
  11662. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11663. }
  11664. }
  11665. }
  11666. else
  11667. {
  11668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11669. }
  11670. end:
  11671. json_object_put(RemoteStartTransaction);
  11672. sendRemoteStartConfirmation(uuid, comfirmstr);
  11673. return result;
  11674. }
  11675. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11676. {
  11677. mtrace();
  11678. int result = FAIL;
  11679. int match = FALSE;
  11680. int GunNO = 0;
  11681. int tempIndex = 0;
  11682. int transactionIdInt=0;
  11683. int transactionIdIsNULL= TRUE;
  11684. char comfirmstr[20];
  11685. json_object *RemoteStopTransaction;
  11686. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11687. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11688. if(server_pending == TRUE)
  11689. {
  11690. return 0;
  11691. }
  11692. RemoteStopTransaction = json_tokener_parse(payload);
  11693. if(!is_error(RemoteStopTransaction))
  11694. {
  11695. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11696. {
  11697. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11698. transactionIdIsNULL = FALSE;
  11699. }
  11700. }
  11701. json_object_put(RemoteStopTransaction);
  11702. if(transactionIdIsNULL == FALSE)
  11703. {
  11704. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11705. {
  11706. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11707. {
  11708. //check Transaction active
  11709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11710. {
  11711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11712. {
  11713. tempIndex = ((gun_index==2) ? 1: 0);
  11714. }
  11715. else
  11716. {
  11717. tempIndex = gun_index;
  11718. }
  11719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11720. {
  11721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11722. {
  11723. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11724. {
  11725. match = TRUE;
  11726. GunNO = gun_index;
  11727. }
  11728. }
  11729. }// END FOR CHAdeMO_QUANTITY
  11730. }
  11731. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11732. {
  11733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11734. {
  11735. tempIndex = ((gun_index==2) ? 1: 0);
  11736. }
  11737. else
  11738. {
  11739. tempIndex = gun_index;
  11740. }
  11741. for (int index = 0; index < CCS_QUANTITY; index++)
  11742. {
  11743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11744. {
  11745. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11746. {
  11747. match = TRUE;
  11748. GunNO = gun_index;
  11749. }
  11750. }
  11751. }// END FOR CCS_QUANTITY
  11752. }
  11753. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11754. {
  11755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11756. {
  11757. tempIndex = ((gun_index==2) ? 1: 0);
  11758. }
  11759. else
  11760. {
  11761. tempIndex = gun_index;
  11762. }
  11763. for (int index = 0; index < GB_QUANTITY; index++)
  11764. {
  11765. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11766. {
  11767. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11768. {
  11769. match = TRUE;
  11770. GunNO = gun_index;
  11771. }
  11772. }
  11773. }// END FOR GB_QUANTITY
  11774. }
  11775. else if(gunType[gun_index] == GUN_TYPE_DO)
  11776. {
  11777. tempIndex = gun_index;
  11778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11779. {
  11780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11781. {
  11782. 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
  11783. {
  11784. match = TRUE;
  11785. GunNO = gun_index;
  11786. }
  11787. }
  11788. }// END FOR GB_QUANTITY
  11789. }
  11790. else
  11791. {
  11792. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11793. {
  11794. tempIndex = 2;
  11795. }
  11796. else
  11797. {
  11798. tempIndex = gun_index;
  11799. }
  11800. for (int index = 0; index < AC_QUANTITY; index++)
  11801. {
  11802. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11803. {
  11804. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11805. {
  11806. match = TRUE;
  11807. GunNO = gun_index;
  11808. }
  11809. }
  11810. }// END FOR CHAdeMO_QUANTITY
  11811. } // END FOR AC ELSE
  11812. }// CHECK IF ResponseTransactionId == transactionIdInt
  11813. }//END FOR
  11814. if( match == TRUE)
  11815. {
  11816. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11818. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11819. }
  11820. else
  11821. {
  11822. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11823. }
  11824. }
  11825. else
  11826. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11827. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11828. return result;
  11829. }
  11830. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11831. {
  11832. mtrace();
  11833. int result = FAIL;
  11834. int connectorIdInt=0, reservationIdInt=0;
  11835. int tempIndex = 0;
  11836. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11837. char comfirmstr[20]={0};
  11838. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11839. int c = 0;
  11840. char *loc;
  11841. //char *ptr;
  11842. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11843. strcpy(sstrtemp, stringtrimspace(payload));
  11844. //***(1)connectorId ****/
  11845. c=0;
  11846. loc = strstr(sstrtemp, "connectorId");
  11847. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11848. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11849. {
  11850. sstr[c] = loc[strlen("connectorId")+2+c];
  11851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11852. c++;
  11853. }
  11854. sstr[c] = '\0';
  11855. connectorIdInt = atoi(sstr);
  11856. //***(2)expiryDate ****/
  11857. loc = strstr(sstrtemp, "expiryDate");
  11858. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11859. c = 0;
  11860. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11861. {
  11862. sstr[c] = loc[3+strlen("expiryDate")+c];
  11863. c++;
  11864. }
  11865. sstr[c] = '\0';
  11866. strcpy(expiryDatestr, sstr);
  11867. //***(3)idTag ****/
  11868. loc = strstr(sstrtemp, "idTag");
  11869. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11870. c = 0;
  11871. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11872. {
  11873. sstr[c] = loc[3+strlen("idTag")+c];
  11874. c++;
  11875. }
  11876. sstr[c] = '\0';
  11877. strcpy(idTagstr, sstr);
  11878. //***(4)parentIdTag ****/
  11879. loc = strstr(sstrtemp, "parentIdTag");
  11880. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11881. c = 0;
  11882. if(loc == NULL)
  11883. {
  11884. strcpy(parentIdTagstr, "");
  11885. }
  11886. else
  11887. {
  11888. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11889. {
  11890. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11891. c++;
  11892. }
  11893. sstr[c] = '\0';
  11894. strcpy(parentIdTagstr, sstr);
  11895. }
  11896. //***(5)reservationId ****/
  11897. c=0;
  11898. loc = strstr(sstrtemp, "reservationId");
  11899. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11900. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11901. {
  11902. sstr[c] = loc[strlen("reservationId")+2+c];
  11903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11904. c++;
  11905. }
  11906. sstr[c] = '\0';
  11907. reservationIdInt = atoi(sstr);
  11908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11909. /*
  11910. enum SYSTEM_STATUS
  11911. {
  11912. SYS_MODE_BOOTING = 0,
  11913. SYS_MODE_IDLE = 1,
  11914. SYS_MODE_AUTHORIZING = 2,
  11915. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11916. SYS_MODE_REASSIGN = 4,
  11917. SYS_MODE_PREPARING = 5,
  11918. SYS_MODE_PREPARE_FOR_EV = 6,
  11919. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11920. SYS_MODE_CHARGING = 8,
  11921. SYS_MODE_TERMINATING = 9,
  11922. SYS_MODE_COMPLETE = 10,
  11923. SYS_MODE_ALARM = 11,
  11924. SYS_MODE_FAULT = 12,
  11925. SYS_MODE_RESERVATION = 13,
  11926. SYS_MODE_BOOKING = 14,
  11927. SYS_MODE_MAINTAIN = 15,
  11928. SYS_MODE_DEBUG = 16,
  11929. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11930. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11931. SYS_MODE_UPDATE = 19
  11932. };
  11933. */
  11934. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11935. {
  11936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11937. goto end;
  11938. }
  11939. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11940. {
  11941. //check Transaction active
  11942. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11943. {
  11944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11945. {
  11946. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11947. }
  11948. else
  11949. {
  11950. tempIndex = connectorIdInt -1;
  11951. }
  11952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11953. {
  11954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11955. {
  11956. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11957. {
  11958. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11959. {
  11960. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11961. {
  11962. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11963. {
  11964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11965. }
  11966. else
  11967. {
  11968. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11970. }
  11971. }
  11972. 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'))
  11973. {
  11974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11975. }
  11976. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11977. {
  11978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11979. }
  11980. else
  11981. {
  11982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11983. }
  11984. }
  11985. 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
  11986. {
  11987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11988. }
  11989. }
  11990. else
  11991. {
  11992. //replace reservation
  11993. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11995. }
  11996. }
  11997. } // END FOR CHAdeMO_QUANTITY
  11998. }
  11999. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12000. {
  12001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12002. {
  12003. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12004. }
  12005. else
  12006. {
  12007. tempIndex = connectorIdInt -1;
  12008. }
  12009. for (int index = 0; index < CCS_QUANTITY; index++)
  12010. {
  12011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12012. {
  12013. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12014. {
  12015. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12016. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12017. {
  12018. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12019. {
  12020. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12021. {
  12022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12023. }
  12024. else
  12025. {
  12026. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12028. }
  12029. }
  12030. 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'))
  12031. {
  12032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12033. }
  12034. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12035. {
  12036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12037. }
  12038. else
  12039. {
  12040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12041. }
  12042. }
  12043. 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
  12044. {
  12045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12046. }
  12047. }
  12048. else
  12049. {
  12050. //replace reservation
  12051. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12053. }
  12054. }
  12055. } // END FOR CCS_QUANTITY
  12056. }
  12057. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12058. {
  12059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12060. {
  12061. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12062. }
  12063. else
  12064. {
  12065. tempIndex = connectorIdInt -1;
  12066. }
  12067. for (int index = 0; index < GB_QUANTITY; index++)
  12068. {
  12069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12070. {
  12071. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12072. {
  12073. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12074. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12075. {
  12076. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12077. {
  12078. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12079. {
  12080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12081. }
  12082. else
  12083. {
  12084. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12086. }
  12087. }
  12088. 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'))
  12089. {
  12090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12091. }
  12092. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12093. {
  12094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12095. }
  12096. else
  12097. {
  12098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12099. }
  12100. }
  12101. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  12102. {
  12103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12104. }
  12105. }
  12106. else
  12107. {
  12108. //replace reservation
  12109. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12111. }
  12112. }
  12113. }// END FOR GB_QUANTITY
  12114. }
  12115. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12116. {
  12117. tempIndex = connectorIdInt -1;
  12118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12119. {
  12120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12121. {
  12122. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12123. {
  12124. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12125. 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
  12126. {
  12127. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12128. {
  12129. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12130. {
  12131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12132. }
  12133. else
  12134. {
  12135. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12137. }
  12138. }
  12139. 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'))
  12140. {
  12141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12142. }
  12143. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12144. {
  12145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12146. }
  12147. else
  12148. {
  12149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12150. }
  12151. }
  12152. 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
  12153. {
  12154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12155. }
  12156. }
  12157. else
  12158. {
  12159. //replace reservation
  12160. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12162. }
  12163. }
  12164. }// END FOR GB_QUANTITY
  12165. }
  12166. else
  12167. {
  12168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12169. {
  12170. tempIndex = 2;
  12171. }
  12172. else
  12173. {
  12174. tempIndex = (connectorIdInt -1);
  12175. }
  12176. for (int index = 0; index < AC_QUANTITY; index++)
  12177. {
  12178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12179. {
  12180. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12181. {
  12182. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12183. {
  12184. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12185. {
  12186. 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))
  12187. {
  12188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12189. }
  12190. else
  12191. {
  12192. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12194. }
  12195. }
  12196. 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'))
  12197. {
  12198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12199. }
  12200. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12201. {
  12202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12203. }
  12204. else
  12205. {
  12206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12207. }
  12208. }
  12209. 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
  12210. {
  12211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12212. }
  12213. }
  12214. else
  12215. {
  12216. //replace reservation
  12217. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12219. }
  12220. }
  12221. } // END FOR AC_QUANTITY
  12222. }
  12223. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12224. }
  12225. else if(connectorIdInt == 0)
  12226. {
  12227. //check Transaction active
  12228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12229. {
  12230. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12231. {
  12232. 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'))
  12233. {
  12234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12235. goto end;
  12236. }
  12237. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12238. {
  12239. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12240. goto end;
  12241. }
  12242. 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
  12243. {
  12244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12245. goto end;
  12246. }
  12247. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12248. {
  12249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12250. goto end;
  12251. }
  12252. }
  12253. }// END FOR CHAdeMO_QUANTITY
  12254. for (int index = 0; index < CCS_QUANTITY; index++)
  12255. {
  12256. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12257. {
  12258. 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'))
  12259. {
  12260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12261. goto end;
  12262. }
  12263. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12264. {
  12265. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12266. goto end;
  12267. }
  12268. 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
  12269. {
  12270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12271. goto end;
  12272. }
  12273. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12274. {
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12276. goto end;
  12277. }
  12278. }
  12279. } // END FOR CCS_QUANTITY
  12280. for (int index = 0; index < GB_QUANTITY; index++)
  12281. {
  12282. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12283. {
  12284. 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'))
  12285. {
  12286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12287. goto end;
  12288. }
  12289. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12290. {
  12291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12292. goto end;
  12293. }
  12294. 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
  12295. {
  12296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12297. goto end;
  12298. }
  12299. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12300. {
  12301. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12302. goto end;
  12303. }
  12304. }
  12305. } // END FOR GB_QUANTITY
  12306. for (int index = 0; index < AC_QUANTITY; index++)
  12307. {
  12308. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12309. {
  12310. 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'))
  12311. {
  12312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12313. goto end;
  12314. }
  12315. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12316. {
  12317. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12318. goto end;
  12319. }
  12320. 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
  12321. {
  12322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12323. goto end;
  12324. }
  12325. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12326. {
  12327. 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))
  12328. {
  12329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12330. goto end;
  12331. }
  12332. }
  12333. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12334. {
  12335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12336. goto end;
  12337. }
  12338. }
  12339. }// END FOR AC_QUANTITY
  12340. //The connectorId is 0
  12341. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12343. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12344. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12345. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12346. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12347. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12348. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12349. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12350. result = TRUE;
  12351. return result;
  12352. }
  12353. else
  12354. {
  12355. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12356. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12357. }
  12358. if(strcmp(comfirmstr,"Accepted") == 0)
  12359. {
  12360. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12361. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12362. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12363. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12364. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12365. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12366. result = TRUE;
  12367. return result;
  12368. }
  12369. end:
  12370. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12371. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12372. return result;
  12373. }
  12374. int handleResetRequest(char *uuid, char *payload)
  12375. {
  12376. mtrace();
  12377. int result = FAIL;
  12378. char sstr[10]={0},sstrtemp[30]={ 0 };
  12379. char typestr[10]={0};
  12380. char comfirmstr[20]={0};
  12381. int c = 0;
  12382. char *loc;
  12383. DEBUG_INFO("handleResetRequest...\n");
  12384. strcpy(sstrtemp, stringtrimspace(payload));
  12385. loc = strstr(sstrtemp, "type");
  12386. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12387. c = 0;
  12388. while (loc[3+strlen("type")+c] != '\"')
  12389. {
  12390. sstr[c] = loc[3+strlen("type")+c];
  12391. c++;
  12392. }
  12393. sstr[c] = '\0';
  12394. strcpy(typestr,sstr);
  12395. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12396. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12397. {
  12398. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12399. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12400. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12401. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12402. }
  12403. else
  12404. {
  12405. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12406. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12407. result = PASS;
  12408. }
  12409. sendResetConfirmation(uuid, comfirmstr);
  12410. return result;
  12411. }
  12412. int handleSendLocalListRequest(char *uuid, char *payload)
  12413. {
  12414. mtrace();
  12415. int result = FAIL;
  12416. char comfirmstr[20];
  12417. int checkState_Faulted = FALSE;
  12418. json_object *SendLocalList;
  12419. DEBUG_INFO("handleSendLocalListRequest...\n");
  12420. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12421. {
  12422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12423. goto end;
  12424. }
  12425. //check Charge Point state
  12426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12427. {
  12428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12429. {
  12430. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12431. }
  12432. }
  12433. for (int index = 0; index < CCS_QUANTITY; index++)
  12434. {
  12435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12436. {
  12437. checkState_Faulted = TRUE; //OCPP Status
  12438. }
  12439. }
  12440. for (int index = 0; index < GB_QUANTITY; index++)
  12441. {
  12442. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12443. {
  12444. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12445. }
  12446. }
  12447. //check Charge Point state
  12448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12449. {
  12450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12451. {
  12452. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12453. }
  12454. }
  12455. //check Charge Point state
  12456. for (int index = 0; index < AC_QUANTITY; index++)
  12457. {
  12458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12459. {
  12460. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12461. }
  12462. }
  12463. if(checkState_Faulted == TRUE)
  12464. {
  12465. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12466. goto end;
  12467. }
  12468. // Parsing payload
  12469. SendLocalList = json_tokener_parse(payload);
  12470. if(!is_error(SendLocalList))
  12471. {
  12472. // Required data
  12473. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12474. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12475. // Optional data
  12476. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12477. {
  12478. //Check UpdateType
  12479. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12480. {
  12481. //Local list full update
  12482. DEBUG_INFO("Local list full update.\n");
  12483. locallistVersion = 0;
  12484. OCPP_getListVerion();
  12485. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12486. {
  12487. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12488. goto end;
  12489. }*/
  12490. OCPP_cleanLocalList();
  12491. }
  12492. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12493. {
  12494. //Local list different update
  12495. DEBUG_INFO("Local list different update.\n");
  12496. locallistVersion = 0;
  12497. OCPP_getListVerion();
  12498. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12499. {
  12500. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12501. goto end;
  12502. }
  12503. }
  12504. else
  12505. {
  12506. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12507. goto end;
  12508. }
  12509. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12510. {
  12511. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12512. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12513. goto end;
  12514. }
  12515. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12516. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12517. {
  12518. 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")));
  12519. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12520. {
  12521. 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")));
  12522. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12523. 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")));
  12524. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12525. 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")));
  12526. }
  12527. // Add to db
  12528. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12529. {
  12530. //Local list full update
  12531. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12532. idx,
  12533. ShmOCPP16Data->SendLocalList.ListVersion,
  12534. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12535. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12536. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12537. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12538. // update list
  12539. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12540. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12541. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12542. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12543. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12544. }
  12545. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12546. {
  12547. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12548. idx,
  12549. ShmOCPP16Data->SendLocalList.ListVersion,
  12550. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12551. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12552. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12553. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12554. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12555. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12556. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12557. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12558. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12559. }
  12560. }
  12561. }
  12562. else
  12563. {
  12564. //Check UpdateType
  12565. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12566. {
  12567. //Local list full update
  12568. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12569. OCPP_cleanLocalList();
  12570. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12571. goto end;
  12572. }
  12573. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12574. {
  12575. //Local list different update
  12576. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12577. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12578. goto end;
  12579. }
  12580. }
  12581. result = PASS;
  12582. }
  12583. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12584. end:
  12585. json_object_put(SendLocalList);
  12586. sendSendLocalListConfirmation(uuid, comfirmstr);
  12587. return result;
  12588. }
  12589. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12590. {
  12591. mtrace();
  12592. int result = FAIL;
  12593. struct StructSetChargingProfile SetProfileReq = {0};
  12594. int tempchargingProfileIdInt;
  12595. int tempstackLevelInt;
  12596. int chargingSchedulePeriodCount = 0;
  12597. char comfirmstr[20]={0};
  12598. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12599. char rmFileCmd[128]={0};
  12600. int profileQuantity = 0;
  12601. int replaceableProfileCnt = 0;
  12602. json_object *SetChargingProfile;
  12603. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12604. SetChargingProfile = json_tokener_parse(payload);
  12605. if(!is_error(SetChargingProfile))
  12606. {
  12607. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12608. {
  12609. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12610. }
  12611. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12612. {
  12613. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12614. {
  12615. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12616. }
  12617. else
  12618. {
  12619. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12620. DEBUG_WARN("Cannot find chargingProfileId field.");
  12621. goto end;
  12622. }
  12623. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12624. {
  12625. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12626. }
  12627. else
  12628. {
  12629. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12630. DEBUG_WARN("Cannot find stackLevel field.");
  12631. goto end;
  12632. }
  12633. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12634. {
  12635. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12636. }
  12637. else
  12638. {
  12639. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12640. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12641. goto end;
  12642. }
  12643. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12644. {
  12645. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12646. }
  12647. else
  12648. {
  12649. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12650. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12651. goto end;
  12652. }
  12653. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12654. {
  12655. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12656. }
  12657. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12658. {
  12659. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12660. }
  12661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12662. {
  12663. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12664. }
  12665. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12666. {
  12667. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12668. }
  12669. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12670. {
  12671. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12672. {
  12673. 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")));
  12674. }
  12675. else
  12676. {
  12677. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12678. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12679. goto end;
  12680. }
  12681. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12682. {
  12683. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12684. }
  12685. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12686. {
  12687. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12688. }
  12689. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12690. {
  12691. 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")));
  12692. }
  12693. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12694. {
  12695. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12696. if(chargingSchedulePeriodCount <= 10)
  12697. {
  12698. 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++)
  12699. {
  12700. 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)
  12701. {
  12702. 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"));
  12703. }
  12704. else
  12705. {
  12706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12707. DEBUG_WARN("Cannot find startPeriod field.");
  12708. goto end;
  12709. }
  12710. 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)
  12711. {
  12712. 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"));
  12713. }
  12714. else
  12715. {
  12716. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12717. DEBUG_WARN("Cannot find limit field.");
  12718. goto end;
  12719. }
  12720. 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)
  12721. {
  12722. 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"));
  12723. }
  12724. }
  12725. }
  12726. }
  12727. else
  12728. {
  12729. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12730. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12731. goto end;
  12732. }
  12733. }
  12734. else
  12735. {
  12736. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12737. DEBUG_WARN("Cannot find chargingSchedule field.");
  12738. goto end;
  12739. }
  12740. }
  12741. }
  12742. // Profile periods quantity check
  12743. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12744. {
  12745. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12746. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12747. goto end;
  12748. }
  12749. // Check invalid limit
  12750. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12751. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12752. {
  12753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12754. {
  12755. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12756. {
  12757. 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)))) ||
  12758. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12759. {
  12760. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12761. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12762. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12763. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12764. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12765. goto end;
  12766. }
  12767. }
  12768. }
  12769. else
  12770. {
  12771. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12772. {
  12773. 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) ||
  12774. (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)))
  12775. {
  12776. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12777. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12778. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12779. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12780. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12781. goto end;
  12782. }
  12783. }
  12784. }
  12785. }
  12786. // Profile purpose info check
  12787. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12788. {
  12789. FILE *fp;
  12790. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12791. if(SetProfileReq.ConnectorId != 0)
  12792. {
  12793. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12794. DEBUG_WARN("Profile connector id is not 0.\n");
  12795. goto end;
  12796. }
  12797. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12798. if (!fp)
  12799. {
  12800. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12801. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12802. }
  12803. else
  12804. {
  12805. char *line = NULL;
  12806. size_t len = 0;
  12807. while(getline(&line, &len, fp) != -1)
  12808. {
  12809. json_object *obj = NULL;
  12810. obj = json_tokener_parse(line);
  12811. if(is_error(obj))
  12812. {
  12813. DEBUG_ERROR("Parse txProfile from file error.\n");
  12814. }
  12815. else
  12816. {
  12817. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12818. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12819. {
  12820. profileQuantity += 1;
  12821. }
  12822. else
  12823. replaceableProfileCnt += 1;
  12824. }
  12825. }
  12826. }
  12827. fclose(fp);
  12828. }
  12829. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12830. {
  12831. FILE *fp;
  12832. char filename[128]={0};
  12833. int tmpProfileQuantity;
  12834. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12835. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12836. {
  12837. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12838. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12839. goto end;
  12840. }
  12841. if(SetProfileReq.ConnectorId == 0)
  12842. {
  12843. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12844. {
  12845. tmpProfileQuantity = 0;
  12846. memset(filename, 0, ARRAY_SIZE(filename));
  12847. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12848. fp = fopen(filename, "r");
  12849. if (!fp)
  12850. {
  12851. DEBUG_INFO("%s does not create.\n", filename);
  12852. fp = fopen(filename, "w+");
  12853. }
  12854. else
  12855. {
  12856. char *line = NULL;
  12857. size_t len = 0;
  12858. while(getline(&line, &len, fp) != -1)
  12859. {
  12860. json_object *obj = NULL;
  12861. obj = json_tokener_parse(line);
  12862. if(is_error(obj))
  12863. {
  12864. DEBUG_ERROR("Parse txProfile from file error.\n");
  12865. }
  12866. else
  12867. {
  12868. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12869. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12870. {
  12871. tmpProfileQuantity += 1;
  12872. }
  12873. else
  12874. replaceableProfileCnt += 1;
  12875. }
  12876. }
  12877. }
  12878. fclose(fp);
  12879. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12880. }
  12881. }
  12882. else
  12883. {
  12884. memset(filename, 0, ARRAY_SIZE(filename));
  12885. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12886. fp = fopen(filename, "r");
  12887. if (!fp)
  12888. {
  12889. DEBUG_INFO("%s does not create.\n", filename);
  12890. fp = fopen(filename, "w+");
  12891. }
  12892. else
  12893. {
  12894. char *line = NULL;
  12895. size_t len = 0;
  12896. while(getline(&line, &len, fp) != -1)
  12897. {
  12898. json_object *obj = NULL;
  12899. obj = json_tokener_parse(line);
  12900. if(is_error(obj))
  12901. {
  12902. DEBUG_ERROR("Parse txProfile from file error.\n");
  12903. }
  12904. else
  12905. {
  12906. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12907. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12908. {
  12909. profileQuantity += 1;
  12910. }
  12911. else
  12912. replaceableProfileCnt += 1;
  12913. }
  12914. }
  12915. }
  12916. fclose(fp);
  12917. }
  12918. }
  12919. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12920. {
  12921. int isMatchTransactiodId= FALSE;
  12922. FILE *fp;
  12923. char filename[128]={0};
  12924. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12925. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12926. if(SetProfileReq.ConnectorId == 0)
  12927. {
  12928. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12929. DEBUG_WARN("Profile connector id is 0.\n");
  12930. goto end;
  12931. }
  12932. int tempIndex = 0;
  12933. //check Transaction active
  12934. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12935. {
  12936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12937. {
  12938. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12939. }
  12940. else
  12941. {
  12942. tempIndex = SetProfileReq.ConnectorId -1;
  12943. }
  12944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12945. {
  12946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12947. {
  12948. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12949. {
  12950. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12951. {
  12952. isMatchTransactiodId = TRUE;
  12953. break;
  12954. }
  12955. }
  12956. }
  12957. }
  12958. }
  12959. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12960. {
  12961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12962. {
  12963. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12964. }
  12965. else
  12966. {
  12967. tempIndex = SetProfileReq.ConnectorId -1;
  12968. }
  12969. for (int index = 0; index < CCS_QUANTITY; index++)
  12970. {
  12971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12972. {
  12973. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12974. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12975. {
  12976. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12977. {
  12978. isMatchTransactiodId = TRUE;
  12979. break;
  12980. }
  12981. }
  12982. }
  12983. }
  12984. }
  12985. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12986. {
  12987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12988. {
  12989. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12990. }
  12991. else
  12992. {
  12993. tempIndex = SetProfileReq.ConnectorId -1;
  12994. }
  12995. for (int index = 0; index < GB_QUANTITY; index++)
  12996. {
  12997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12998. {
  12999. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13000. {
  13001. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13002. {
  13003. isMatchTransactiodId = TRUE;
  13004. break;
  13005. }
  13006. }
  13007. }
  13008. }
  13009. }
  13010. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13011. {
  13012. tempIndex = SetProfileReq.ConnectorId -1;
  13013. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13014. {
  13015. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13016. {
  13017. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13018. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13019. {
  13020. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13021. {
  13022. isMatchTransactiodId = TRUE;
  13023. break;
  13024. }
  13025. }
  13026. }
  13027. }
  13028. }
  13029. else
  13030. {
  13031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13032. {
  13033. tempIndex = 2;
  13034. }
  13035. else
  13036. {
  13037. tempIndex = (SetProfileReq.ConnectorId -1);
  13038. }
  13039. for (int index = 0; index < AC_QUANTITY; index++)
  13040. {
  13041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13042. {
  13043. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13044. {
  13045. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13046. {
  13047. isMatchTransactiodId = TRUE;
  13048. break;
  13049. }
  13050. }
  13051. }
  13052. }
  13053. }
  13054. //check Transaction active
  13055. if(isMatchTransactiodId == FALSE)
  13056. {
  13057. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13058. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13059. goto end;
  13060. }
  13061. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13062. {
  13063. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13064. DEBUG_WARN("Connector id is over max gun number.\n");
  13065. goto end;
  13066. }
  13067. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13068. fp = fopen(filename, "r");
  13069. if (!fp)
  13070. {
  13071. DEBUG_INFO("%s does not create.\n", filename);
  13072. fp = fopen(filename, "w+");
  13073. }
  13074. else
  13075. {
  13076. char *line = NULL;
  13077. size_t len = 0;
  13078. while(getline(&line, &len, fp) != -1)
  13079. {
  13080. json_object *obj = NULL;
  13081. obj = json_tokener_parse(line);
  13082. if(is_error(obj))
  13083. {
  13084. DEBUG_ERROR("Parse txProfile from file error.\n");
  13085. }
  13086. else
  13087. {
  13088. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13089. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13090. {
  13091. profileQuantity += 1;
  13092. }
  13093. else
  13094. replaceableProfileCnt += 1;
  13095. }
  13096. }
  13097. }
  13098. fclose(fp);
  13099. }
  13100. // Check ChargeProfileMaxStackLevel
  13101. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13102. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13103. {
  13104. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13105. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13106. goto end;
  13107. }
  13108. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13109. {
  13110. FILE *fp;
  13111. char dataLine[4096]={0};
  13112. char fnametemp[128]={0};
  13113. int tmpProfileQuantity;
  13114. //Check ChargePointMaxProfile.json exit
  13115. profileQuantity = 0;
  13116. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13117. {
  13118. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13119. //Check Charging Profile Count
  13120. tmpProfileQuantity = 0;
  13121. while(fscanf(fp, "%s", dataLine) != EOF)
  13122. {
  13123. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13124. {
  13125. profileQuantity += 1;
  13126. tmpProfileQuantity += 1;
  13127. }
  13128. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13129. }
  13130. fclose(fp);
  13131. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13132. }
  13133. //Check TxDefaultProfile_%d.json
  13134. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13135. {
  13136. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13137. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13138. if((access(fnametemp,F_OK))!=-1)
  13139. {
  13140. fp = fopen(fnametemp, "r");
  13141. //Check Charging Profile Count
  13142. tmpProfileQuantity = 0;
  13143. while(fscanf(fp, "%s", dataLine) != EOF)
  13144. {
  13145. //DEBUG_INFO("word=%s\n",word);
  13146. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13147. {
  13148. profileQuantity += 1;
  13149. tmpProfileQuantity += 1;
  13150. }
  13151. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13152. }
  13153. fclose(fp);
  13154. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13155. }
  13156. }
  13157. //Check TxProfile_%d.json
  13158. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13159. {
  13160. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13161. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13162. if((access(fnametemp,F_OK))!=-1)
  13163. {
  13164. fp = fopen(fnametemp, "r");
  13165. //Check Charging Profile Count
  13166. tmpProfileQuantity = 0;
  13167. while(fscanf(fp, "%s", dataLine) != EOF)
  13168. {
  13169. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13170. {
  13171. profileQuantity += 1;
  13172. tmpProfileQuantity += 1;
  13173. }
  13174. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13175. }
  13176. fclose(fp);
  13177. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13178. }
  13179. }
  13180. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13181. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13182. // To check total Profile quantity
  13183. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13184. {
  13185. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13186. {
  13187. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13188. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13189. goto end;
  13190. }
  13191. }
  13192. else
  13193. {
  13194. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13195. {
  13196. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13197. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13198. goto end;
  13199. }
  13200. }
  13201. }
  13202. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13203. //**********************************Write to File********************************************************/
  13204. {
  13205. FILE *infile;
  13206. FILE *outfile;
  13207. char dataLine[4096]={0};
  13208. char filename[128]={0};
  13209. int chkChar=0;
  13210. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13211. {
  13212. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13213. {
  13214. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13215. }
  13216. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13217. {
  13218. if(SetProfileReq.ConnectorId==0)
  13219. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13220. else
  13221. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13222. }
  13223. else
  13224. {
  13225. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13226. }
  13227. infile = fopen (filename, "r");
  13228. outfile = fopen (tempfile, "w");
  13229. chkChar = fgetc(infile);
  13230. rewind(infile);
  13231. if(chkChar == EOF)
  13232. {
  13233. // Profile is empty
  13234. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13235. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13236. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13237. fclose(infile);
  13238. fclose(outfile);
  13239. sprintf(rmFileCmd,"rm -f %s",filename);
  13240. system(rmFileCmd);
  13241. rename(tempfile, filename);
  13242. }
  13243. else
  13244. {
  13245. // Profile is not empty
  13246. int ChargingProfileAdded = FALSE;
  13247. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13248. {
  13249. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13250. json_object *tmpChargingProfile;
  13251. tmpChargingProfile = json_tokener_parse(dataLine);
  13252. if(!is_error(SetChargingProfile))
  13253. {
  13254. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13255. {
  13256. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13257. {
  13258. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13259. }
  13260. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13261. {
  13262. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13263. }
  13264. }
  13265. }
  13266. json_object_put(tmpChargingProfile);
  13267. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13268. {
  13269. if(ChargingProfileAdded == FALSE)
  13270. {
  13271. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13272. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13273. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13274. ChargingProfileAdded = TRUE;
  13275. }
  13276. }
  13277. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13278. {
  13279. if(ChargingProfileAdded == FALSE)
  13280. {
  13281. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13282. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13283. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13284. ChargingProfileAdded = TRUE;
  13285. }
  13286. }
  13287. else
  13288. {
  13289. fprintf(outfile,"%s\n",dataLine);
  13290. if(ChargingProfileAdded == FALSE)
  13291. {
  13292. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13293. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13294. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13295. ChargingProfileAdded = TRUE;
  13296. }
  13297. }
  13298. } // end of while loop
  13299. fclose(infile);
  13300. fclose(outfile);
  13301. sprintf(rmFileCmd,"rm -f %s",filename);
  13302. system(rmFileCmd);
  13303. rename(tempfile, filename);
  13304. }
  13305. }
  13306. sleep(1);
  13307. result = TRUE;
  13308. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13309. }
  13310. end:
  13311. json_object_put(SetChargingProfile);
  13312. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13313. {
  13314. if(SetProfileReq.ConnectorId == 0)
  13315. {
  13316. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13317. {
  13318. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13319. }
  13320. }
  13321. else
  13322. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13323. }
  13324. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13325. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13326. return result;
  13327. }
  13328. int handleTriggerMessageRequest(char *uuid, char *payload)
  13329. {
  13330. mtrace();
  13331. int result = FAIL;
  13332. int connectorIdIsNULL = FALSE;
  13333. int connectorIdInt =0;
  13334. char sstr[40]={0},sstrtemp[100]={ 0 };
  13335. char requestedMessagestr[40]={0};
  13336. char comfirmstr[20]={0};
  13337. int c = 0;
  13338. char *loc;
  13339. DEBUG_INFO("handleTriggerMessageRequest\n");
  13340. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13341. strcpy(sstrtemp, stringtrimspace(payload));
  13342. c = 0;
  13343. loc = strstr(sstrtemp, "requestedMessage");
  13344. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13345. {
  13346. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13347. c++;
  13348. }
  13349. sstr[c] = '\0';
  13350. strcpy(requestedMessagestr, sstr);
  13351. c = 0;
  13352. loc = strstr(sstrtemp, "connectorId");
  13353. if(loc == NULL)
  13354. {
  13355. connectorIdIsNULL = TRUE;
  13356. }
  13357. else
  13358. {
  13359. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13360. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13361. {
  13362. sstr[c] = loc[strlen("connectorId")+2+c];
  13363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13364. c++;
  13365. }
  13366. sstr[c] = '\0';
  13367. connectorIdInt = atoi(sstr);
  13368. }
  13369. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13370. {
  13371. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13372. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13373. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13374. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13375. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13376. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13377. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13378. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13379. {
  13380. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13381. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13382. return TRUE;
  13383. }
  13384. else
  13385. {
  13386. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13387. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13388. }
  13389. }
  13390. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13391. {
  13392. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13393. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13394. return TRUE;
  13395. }
  13396. //==========================
  13397. // Trigger message
  13398. //==========================
  13399. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13400. {
  13401. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13402. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13403. {
  13404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13405. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13406. }
  13407. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13408. }
  13409. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13410. {
  13411. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13412. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13413. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13414. }
  13415. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13416. {
  13417. //sendBootNotificationRequest();
  13418. server_sign = FALSE;
  13419. }
  13420. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13421. {
  13422. refreshStartTimer(&clientTime.Heartbeat);
  13423. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13424. }
  13425. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13426. {
  13427. if(connectorIdIsNULL == FALSE)
  13428. {
  13429. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13430. {
  13431. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13432. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13433. }
  13434. }
  13435. else
  13436. {
  13437. for(int idx=0;idx< gunTotalNumber;idx++)
  13438. {
  13439. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13440. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13441. }
  13442. }
  13443. }
  13444. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13445. {
  13446. if(connectorIdIsNULL == FALSE)
  13447. {
  13448. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13449. {
  13450. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13451. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13452. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13453. }
  13454. }
  13455. else
  13456. {
  13457. for(int idx=0;idx< gunTotalNumber;idx++)
  13458. {
  13459. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13460. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13461. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13462. }
  13463. }
  13464. }
  13465. return result;
  13466. }
  13467. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13468. {
  13469. mtrace();
  13470. int result = FAIL;
  13471. int connectorIdInt =0;
  13472. char comfirmstr[20]={0};
  13473. int tempIndex = 0;
  13474. json_object *UnlockConnector;
  13475. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13476. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13477. UnlockConnector = json_tokener_parse(payload);
  13478. if(!is_error(UnlockConnector))
  13479. {
  13480. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13481. {
  13482. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13483. }
  13484. }
  13485. json_object_put(UnlockConnector);
  13486. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13487. if(gunTotalNumber == 0)
  13488. {
  13489. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13490. goto end;
  13491. }
  13492. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13493. {
  13494. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13495. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13496. goto end;
  13497. }
  13498. else
  13499. {
  13500. //check Transaction active
  13501. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13502. {
  13503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13504. {
  13505. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13506. }
  13507. else
  13508. {
  13509. tempIndex = connectorIdInt -1;
  13510. }
  13511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13512. {
  13513. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13514. {
  13515. //stop Transaction
  13516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13517. }
  13518. }
  13519. }
  13520. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13521. {
  13522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13523. {
  13524. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13525. }
  13526. else
  13527. {
  13528. tempIndex = connectorIdInt -1;
  13529. }
  13530. for (int index = 0; index < CCS_QUANTITY; index++)
  13531. {
  13532. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13533. {
  13534. //stop Transaction
  13535. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13536. }
  13537. }
  13538. }
  13539. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13540. {
  13541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13542. {
  13543. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13544. }
  13545. else
  13546. {
  13547. tempIndex = connectorIdInt -1;
  13548. }
  13549. for (int index = 0; index < GB_QUANTITY; index++)
  13550. {
  13551. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13552. {
  13553. //stop Transaction
  13554. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13555. }
  13556. }
  13557. }
  13558. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13559. {
  13560. tempIndex = connectorIdInt -1;
  13561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13562. {
  13563. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13564. {
  13565. //stop Transaction
  13566. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13567. }
  13568. }
  13569. }
  13570. else
  13571. {
  13572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13573. {
  13574. tempIndex = 2;
  13575. }
  13576. else
  13577. {
  13578. tempIndex = connectorIdInt-1;
  13579. }
  13580. for (int index = 0; index < AC_QUANTITY; index++)
  13581. {
  13582. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13583. {
  13584. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13585. }
  13586. }
  13587. }
  13588. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13589. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13590. result = TRUE;
  13591. return result;
  13592. }
  13593. end:
  13594. //json_object_put(obj); --- remove temporally
  13595. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13596. return result;
  13597. }
  13598. static char UpdateFirmwarepayloadData[300]={0};
  13599. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13600. {
  13601. mtrace();
  13602. int result = FAIL;
  13603. pthread_t t;
  13604. sendUpdateFirmwareConfirmation(uuid);
  13605. memset(UpdateFirmwarepayloadData, 0, 300);
  13606. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13607. if(!interLock.isUpdateFirmwareGoing)
  13608. {
  13609. interLock.isUpdateFirmwareGoing = 1;
  13610. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13611. sleep(1);
  13612. }
  13613. else
  13614. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13615. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13616. return result;
  13617. }
  13618. void *UpdateFirmwareProcess(void *data)
  13619. {
  13620. pthread_detach(pthread_self());
  13621. mtrace();
  13622. int retriesInt =0, retryIntervalInt=0;
  13623. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13624. int port=0;
  13625. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13626. int isSuccess = 0;
  13627. char ftpbuf[1024];
  13628. char temp[1024];
  13629. char * pch;
  13630. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13631. json_object *UpdateFirmware;
  13632. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13633. if(!is_error(UpdateFirmware))
  13634. {
  13635. // Required data
  13636. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13637. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13638. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13639. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13640. // Optional data
  13641. if(json_object_object_get(UpdateFirmware, "retries"))
  13642. {
  13643. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13644. }
  13645. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13646. {
  13647. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13648. }
  13649. }
  13650. json_object_put(UpdateFirmware);
  13651. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13652. memset(path, 0, ARRAY_SIZE(path));
  13653. // Wait retrieveData
  13654. if(strlen(retrieveDatestr) > 10)
  13655. {
  13656. do
  13657. {
  13658. sleep(1);
  13659. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13660. }
  13661. // Ready to download
  13662. system("rm -f /mnt/*");
  13663. if(strncmp(locationstr,"http", 4) == 0)
  13664. {
  13665. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13666. sprintf(ftppath,"/%s", path);
  13667. DEBUG_INFO("locationstr: %s\n", locationstr);
  13668. DEBUG_INFO("protocol: %s\n",protocol);
  13669. DEBUG_INFO("host: %s\n",host);
  13670. DEBUG_INFO("path: %s\n",path);
  13671. DEBUG_INFO("ftppath: %s\n",ftppath);
  13672. int ftppathlen=strlen(ftppath);
  13673. int i=1;
  13674. char filenametemp[50];
  13675. while(i < ftppathlen)
  13676. {
  13677. int len=ftppathlen-i;
  13678. if(ftppath[len]== 47) // '/' ascll code: 47
  13679. {
  13680. DEBUG_INFO("compare '/' all right\n");
  13681. break;
  13682. }
  13683. i=i+1;
  13684. }
  13685. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13686. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13687. filenametemp[i+1] = 0;
  13688. do
  13689. {
  13690. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13691. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13692. sleep(1);
  13693. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13694. if(!isSuccess)
  13695. {
  13696. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13697. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13698. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13699. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13700. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13701. }
  13702. else
  13703. {
  13704. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13705. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13706. }
  13707. retriesInt--;
  13708. }while((isSuccess == 0)&&(retriesInt >= 0));
  13709. }
  13710. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13711. {
  13712. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13713. memset(temp, 0, ARRAY_SIZE(temp));
  13714. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13715. strcpy(ftpbuf, locationstr);
  13716. int ftppathlen=strlen(ftpbuf);
  13717. int i=1;
  13718. char filenametemp[50];
  13719. while(i < ftppathlen)
  13720. {
  13721. int len=ftppathlen-i;
  13722. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13723. {
  13724. DEBUG_INFO(" compare '/' all right\n");
  13725. break;
  13726. }
  13727. i=i+1;
  13728. }
  13729. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13730. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13731. filenametemp[i+1] = 0;
  13732. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13733. pch=strchr(temp,'@');
  13734. if(pch==NULL)
  13735. {
  13736. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13737. protocol, host, &port, path);
  13738. strcpy(user,"anonymous");
  13739. strcpy(password,"");
  13740. }
  13741. else
  13742. {
  13743. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13744. protocol, user, host, &port, path);
  13745. }
  13746. sscanf(host,"%[^/]%s",host1, path1);
  13747. sprintf(ftppath,"%s:/%s", host,path);
  13748. if(port == 0)
  13749. {
  13750. port = 21;
  13751. }
  13752. do
  13753. {
  13754. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13755. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13756. sleep(1);
  13757. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13758. if(!isSuccess)
  13759. {
  13760. //BulldogUtil.sleepMs(interval*1000);
  13761. DEBUG_INFO("Update firmware request and download file fail.\n");
  13762. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13763. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13764. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13765. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13766. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13767. }
  13768. else
  13769. {
  13770. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13771. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13772. }
  13773. retriesInt--;
  13774. }while((!isSuccess)&&(retriesInt >= 0));
  13775. }
  13776. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13777. {
  13778. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13779. memset(temp, 0, ARRAY_SIZE(temp));
  13780. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13781. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13782. int ftppathlen=strlen(ftpbuf);
  13783. int i=1;
  13784. char filenametemp[50];
  13785. while(i < ftppathlen)
  13786. {
  13787. int len=ftppathlen-i;
  13788. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13789. {
  13790. DEBUG_INFO(" compare '/' all right\n");
  13791. break;
  13792. }
  13793. i=i+1;
  13794. }
  13795. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13796. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13797. filenametemp[i+1] = 0;
  13798. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13799. pch=strchr(temp,'@');
  13800. if(pch==NULL)
  13801. {
  13802. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13803. protocol, host, &port, path);
  13804. strcpy(user,"anonymous");
  13805. strcpy(password,"");
  13806. }
  13807. else
  13808. {
  13809. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13810. protocol, user, password, host, &port, path);
  13811. }
  13812. sscanf(host,"%[^/]%s",host1, path1);
  13813. sprintf(ftppath,"%s", path1);
  13814. //DEBUG_INFO("protocol =%s\n",protocol);
  13815. //DEBUG_INFO("user =%s\n",user);
  13816. //DEBUG_INFO("password =%s\n",password);
  13817. //DEBUG_INFO("host1 =%s\n",host1);
  13818. //DEBUG_INFO("port =%d\n",port);
  13819. //DEBUG_INFO("path1 =%s\n",path1);
  13820. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13821. //ftpFile(host, user, password, port, ftppath, fname);
  13822. //download firmware pthred
  13823. if(port == 0)
  13824. {
  13825. port = 21;
  13826. }
  13827. do
  13828. {
  13829. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13830. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13831. sleep(1);
  13832. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13833. if(!isSuccess)
  13834. {
  13835. //BulldogUtil.sleepMs(interval*1000);
  13836. DEBUG_INFO("Update firmware request and download file fail.\n");
  13837. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13838. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13839. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13840. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13841. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13842. }
  13843. else
  13844. {
  13845. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13846. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13847. }
  13848. retriesInt--;
  13849. }while((!isSuccess)&&(retriesInt >= 0));
  13850. }
  13851. else
  13852. {
  13853. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13855. sleep(1);
  13856. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13857. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13858. }
  13859. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13860. interLock.isUpdateFirmwareGoing = 0;
  13861. pthread_exit(NULL);
  13862. }
  13863. int handleCertificateSignedRequest(char *uuid, char *payload)
  13864. {
  13865. mtrace();
  13866. int result = PASS;
  13867. json_object *CertificateSigned;
  13868. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13869. CertificateSigned = json_tokener_parse(payload);
  13870. if(!is_error(CertificateSigned))
  13871. {
  13872. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13873. }
  13874. json_object_put(CertificateSigned);
  13875. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13876. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13877. fclose(fp);
  13878. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13879. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13880. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13881. sendCertificateSignedConfirmation(uuid);
  13882. return result;
  13883. }
  13884. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13885. {
  13886. mtrace();
  13887. int result = PASS;
  13888. json_object *DeleteCertificate;
  13889. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13890. DeleteCertificate = json_tokener_parse(payload);
  13891. if(!is_error(DeleteCertificate))
  13892. {
  13893. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13894. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13895. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13896. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13897. }
  13898. json_object_put(DeleteCertificate);
  13899. /*
  13900. * TODO: Delete certificateSigned process
  13901. */
  13902. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13903. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13904. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13905. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13906. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13907. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13908. sendDeleteCertificateConfirmation(uuid);
  13909. return result;
  13910. }
  13911. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13912. {
  13913. mtrace();
  13914. int result = PASS;
  13915. json_object *ExtendedTriggerMessage;
  13916. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13917. ExtendedTriggerMessage = json_tokener_parse(payload);
  13918. if(!is_error(ExtendedTriggerMessage))
  13919. {
  13920. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13921. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13922. {
  13923. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13924. }
  13925. else
  13926. {
  13927. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13928. }
  13929. }
  13930. json_object_put(ExtendedTriggerMessage);
  13931. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13932. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13933. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13934. {
  13935. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13936. }
  13937. else
  13938. {
  13939. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13940. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13941. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13942. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13943. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13944. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13945. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13946. {
  13947. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13948. }
  13949. else
  13950. {
  13951. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13952. }
  13953. }
  13954. sendExtendedTriggerMessageConfirmation(uuid);
  13955. //==========================
  13956. // Trigger message
  13957. //==========================
  13958. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13959. {
  13960. //sendBootNotificationRequest();
  13961. server_sign = FALSE;
  13962. }
  13963. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13964. {
  13965. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13966. }
  13967. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13968. {
  13969. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13970. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13971. {
  13972. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13973. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13974. }
  13975. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13976. }
  13977. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13978. {
  13979. refreshStartTimer(&clientTime.Heartbeat);
  13980. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13981. }
  13982. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13983. {
  13984. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13985. {
  13986. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13987. }
  13988. else
  13989. {
  13990. for(int idx=0;idx< gunTotalNumber;idx++)
  13991. {
  13992. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13993. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13994. }
  13995. }
  13996. }
  13997. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13998. {
  13999. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14000. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  14001. {
  14002. 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\" &");
  14003. }
  14004. }
  14005. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14006. {
  14007. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14008. {
  14009. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14010. }
  14011. else
  14012. {
  14013. for(int idx=0;idx< gunTotalNumber;idx++)
  14014. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14015. }
  14016. }
  14017. return result;
  14018. }
  14019. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14020. {
  14021. mtrace();
  14022. int result = PASS;
  14023. json_object *GetInstalledCertificateIds;
  14024. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14025. GetInstalledCertificateIds = json_tokener_parse(payload);
  14026. if(!is_error(GetInstalledCertificateIds))
  14027. {
  14028. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14029. }
  14030. json_object_put(GetInstalledCertificateIds);
  14031. /*
  14032. * TODO: Return installed certificate process
  14033. */
  14034. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14035. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14036. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14037. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14038. sendGetInstalledCertificateIdsConfirmation(uuid);
  14039. return result;
  14040. }
  14041. int handleGetLogRequest(char *uuid, char *payload)
  14042. {
  14043. mtrace();
  14044. int result = PASS;
  14045. json_object *GetLog;
  14046. DEBUG_INFO("handleGetLogRequest...\n");
  14047. GetLog = json_tokener_parse(payload);
  14048. if(!is_error(GetLog))
  14049. {
  14050. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14051. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14052. if(json_object_object_get(GetLog, "retries") != NULL)
  14053. {
  14054. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14055. }
  14056. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14057. {
  14058. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14059. }
  14060. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14061. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14062. {
  14063. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14064. }
  14065. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14066. {
  14067. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14068. }
  14069. }
  14070. json_object_put(GetLog);
  14071. /*
  14072. * TODO: Upload log process
  14073. */
  14074. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  14075. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  14076. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  14077. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  14078. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  14079. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  14080. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  14081. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  14082. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14083. sendGetLogConfirmation(uuid);
  14084. return result;
  14085. }
  14086. int handleInstallCertificateRequest(char *uuid, char *payload)
  14087. {
  14088. mtrace();
  14089. int result = PASS;
  14090. json_object *InstallCertificate;
  14091. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14092. InstallCertificate = json_tokener_parse(payload);
  14093. if(!is_error(InstallCertificate))
  14094. {
  14095. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14096. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14097. /*
  14098. * TODO: Install certificate process
  14099. */
  14100. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14101. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14102. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14103. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14104. sendInstallCertificateConfirmation(uuid);
  14105. }
  14106. json_object_put(InstallCertificate);
  14107. return result;
  14108. }
  14109. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14110. {
  14111. mtrace();
  14112. int result = PASS;
  14113. json_object *SignedUpdateFirmware;
  14114. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14115. SignedUpdateFirmware = json_tokener_parse(payload);
  14116. if(!is_error(SignedUpdateFirmware))
  14117. {
  14118. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14119. {
  14120. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14121. }
  14122. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14123. {
  14124. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14125. }
  14126. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14127. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14128. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14129. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14130. {
  14131. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14132. }
  14133. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14134. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14135. }
  14136. json_object_put(SignedUpdateFirmware);
  14137. /*
  14138. * TODO: Upgrade firmware process
  14139. */
  14140. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14141. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  14142. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  14143. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  14144. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14145. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  14146. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  14147. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14148. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14149. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  14150. sendInstallCertificateConfirmation(uuid);
  14151. return result;
  14152. }
  14153. int handleUnknownRequest(char *uuid, char *payload)
  14154. {
  14155. mtrace();
  14156. int result = PASS;
  14157. DEBUG_INFO("handleUnknownRequest...\n");
  14158. sendUnknownConfirmation(uuid);
  14159. result = PASS;
  14160. return result;
  14161. }
  14162. //==========================================
  14163. // Handle server response routine
  14164. //==========================================
  14165. void handleAuthorizeResponse(char *payload, int gun_index)
  14166. {
  14167. mtrace();
  14168. char expiryDatestr[36]={0};
  14169. char parentIdTagstr[21]={0};
  14170. char statusstr[20]={0};
  14171. int expiryDateISNULL=FALSE;
  14172. int parentIdTagISNULL=FALSE;
  14173. DEBUG_INFO("handleAuthorizeResponse...\n");
  14174. json_object *Authorize;
  14175. Authorize = json_tokener_parse(payload);
  14176. if(!is_error(Authorize))
  14177. {
  14178. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14179. {
  14180. // Required data
  14181. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14182. // Optional data
  14183. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14184. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14185. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14186. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14187. }
  14188. }
  14189. json_object_put(Authorize);
  14190. if(expiryDateISNULL == FALSE)
  14191. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14192. if(parentIdTagISNULL == FALSE)
  14193. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14194. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14195. //Update idTag information to authorization cache if supproted
  14196. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14197. {
  14198. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14199. }
  14200. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14201. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14202. authorizeRetryTimes = 0;
  14203. }
  14204. void handleBootNotificationResponse(char *payload, int gun_index)
  14205. {
  14206. mtrace();
  14207. char statusStr[12]={0};
  14208. char currentTimeStr[30]={0};
  14209. int intervalInt = 0;
  14210. DEBUG_INFO("handleBootNotificationResponse...\n");
  14211. json_object *BootNotification;
  14212. BootNotification = json_tokener_parse(payload);
  14213. if(!is_error(BootNotification))
  14214. {
  14215. // Required data
  14216. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14217. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14218. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14219. }
  14220. json_object_put(BootNotification);
  14221. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14222. BootNotificationInterval = intervalInt;
  14223. //write back to ShmOCPP16Data->BootNotification
  14224. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14225. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14226. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14227. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14228. {
  14229. BootNotificationInterval = 0;
  14230. if((intervalInt == 0) || (intervalInt >= 10))
  14231. {
  14232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14233. HeartBeatWaitTime = intervalInt;
  14234. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14235. }
  14236. server_sign = TRUE;
  14237. server_pending =FALSE;
  14238. }
  14239. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14240. {
  14241. server_pending = TRUE;
  14242. }
  14243. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14244. srand(time(NULL));
  14245. refreshStartTimer(&clientTime.Heartbeat);
  14246. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14247. SetOcppConnStatus(TRUE);
  14248. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14249. }
  14250. void handleDataTransferResponse(char *payload, int gun_index)
  14251. {
  14252. json_object *DataTransfer = json_tokener_parse(payload);
  14253. if(!is_error(DataTransfer))
  14254. {
  14255. // Required data
  14256. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14257. // Optional data
  14258. if(json_object_object_get(DataTransfer, "data") != NULL)
  14259. {
  14260. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14261. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14262. if(!is_error(Data))
  14263. {
  14264. if(json_object_object_get(Data, "msgId") != NULL)
  14265. {
  14266. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14267. {
  14268. 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")));
  14269. }
  14270. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14271. {
  14272. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14273. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14274. }
  14275. }
  14276. }
  14277. json_object_put(Data);
  14278. }
  14279. }
  14280. json_object_put(DataTransfer);
  14281. }
  14282. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14283. {
  14284. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14285. //struct json_object *obj;
  14286. // obj = json_tokener_parse(payload);
  14287. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14289. //No fields are defined.
  14290. }
  14291. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14292. {
  14293. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14294. //struct json_object *obj;
  14295. // obj = json_tokener_parse(payload);
  14296. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14297. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14298. //No fields are defined.
  14299. }
  14300. void handleHeartbeatResponse(char *payload, int gun_index)
  14301. {
  14302. mtrace();
  14303. DEBUG_INFO("handleHeartbeatResponse...\n");
  14304. json_object *Heartbeat;
  14305. Heartbeat = json_tokener_parse(payload);
  14306. if(!is_error(Heartbeat))
  14307. {
  14308. // Required data
  14309. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14310. }
  14311. json_object_put(Heartbeat);
  14312. if(FirstHeartBeat == 0)
  14313. {
  14314. FirstHeartBeat = 1;
  14315. DEBUG_INFO("FirstHeartBeat \n");
  14316. }
  14317. HeartBeatWithNOResponse = 0;
  14318. refreshStartTimer(&clientTime.Heartbeat);
  14319. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14320. }
  14321. void handleMeterValuesResponse(char *payload, int gun_index)
  14322. {
  14323. mtrace();
  14324. DEBUG_INFO("handleMeterValuesResponse...\n");
  14325. isQueueSendable = 1;
  14326. }
  14327. void handleStartTransactionResponse(char *payload, int gun_index)
  14328. {
  14329. mtrace();
  14330. //int transactionIdInt = 0;
  14331. FILE *outfile;
  14332. char data[100]={0};
  14333. DEBUG_INFO("handleStartTransactionResponse...\n");
  14334. json_object *StartTransaction;
  14335. StartTransaction = json_tokener_parse(payload);
  14336. if(!is_error(StartTransaction))
  14337. {
  14338. // Required data
  14339. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14340. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14341. // Optional data
  14342. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14343. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14344. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14345. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14346. }
  14347. json_object_put(StartTransaction);
  14348. OCPP_updatePeriodEnergy(gun_index);
  14349. //-----------Start : write to the Queue TransactionId file -----------------//
  14350. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14351. {}
  14352. else
  14353. {
  14354. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14355. if(log == NULL)
  14356. {
  14357. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14358. return ;
  14359. }
  14360. else
  14361. {
  14362. fclose(log);
  14363. }
  14364. }
  14365. // open file for writing
  14366. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14367. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14368. {
  14369. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14370. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14371. fputs(data, outfile);
  14372. fclose (outfile);
  14373. }
  14374. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14375. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14376. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14377. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14378. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14379. isQueueSendable = 1;
  14380. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14381. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14382. }
  14383. void handleStatusNotificationResponse(char *payload, int gun_index)
  14384. {
  14385. mtrace();
  14386. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14387. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14388. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14389. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14390. }
  14391. void handleStopTransactionnResponse(char *payload, int gun_index)
  14392. {
  14393. mtrace();
  14394. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14395. json_object *StopTransaction;
  14396. StopTransaction = json_tokener_parse(payload);
  14397. if(!is_error(StopTransaction))
  14398. {
  14399. // Optional data
  14400. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14401. {
  14402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14403. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14405. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14407. }
  14408. }
  14409. json_object_put(StopTransaction);
  14410. isQueueSendable = 1;
  14411. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14412. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14413. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14414. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14415. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14416. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14417. }
  14418. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14419. {
  14420. mtrace();
  14421. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14422. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14423. }
  14424. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14425. {
  14426. mtrace();
  14427. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14428. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14429. }
  14430. void handleSignCertificateResponse(char *payload, int gun_index)
  14431. {
  14432. mtrace();
  14433. DEBUG_INFO("handleSignCertificateResponse...\n");
  14434. json_object *SignCertificate;
  14435. SignCertificate = json_tokener_parse(payload);
  14436. if(!is_error(SignCertificate))
  14437. {
  14438. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14439. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14440. }
  14441. json_object_put(SignCertificate);
  14442. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14443. }
  14444. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14445. {
  14446. mtrace();
  14447. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14448. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14449. }
  14450. //==========================================
  14451. // Handle Error routine
  14452. //==========================================
  14453. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14454. {
  14455. mtrace();
  14456. #ifdef SystemLogMessage
  14457. DEBUG_INFO("errorCode: %s\n", errorCode);
  14458. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14459. DEBUG_INFO("errorDetails: %s\n", payload);
  14460. #endif
  14461. }
  14462. //===============================================
  14463. // Common routine
  14464. //===============================================
  14465. int initialConfigurationTable(void)
  14466. {
  14467. //clock_t start_t, end_t, total_t;
  14468. FILE *fp;
  14469. FILE *outfile;
  14470. char str[512]={0};
  14471. char sstr[256]={0};
  14472. int c = 0;
  14473. char *loc;
  14474. int confVersion = 18;
  14475. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14476. //start_t = clock();
  14477. //printf("Starting of the program, start_t = %ld\n", start_t);
  14478. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14479. // Check configuration file size is correct
  14480. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14481. {
  14482. struct stat st;
  14483. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14484. if(st.st_size < 3100)
  14485. {
  14486. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14487. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14488. }
  14489. }
  14490. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14491. {
  14492. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14493. if(outfile == NULL)
  14494. {
  14495. DEBUG_INFO("Error opening file\n");
  14496. return FALSE;
  14497. }
  14498. /*Core Profile*/
  14499. //AllowOfflineTxForUnknownId
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14504. //AuthorizationCacheEnabled
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14509. //AuthorizeRemoteTxRequests
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14514. //BlinkRepeat
  14515. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14519. //ClockAlignedDataInterval
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14524. //ConnectionTimeOut
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14529. //GetConfigurationMaxKeys
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14534. // HeartbeatInterval
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14539. // LightIntensity
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14544. // LocalAuthorizeOffline
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14549. // LocalPreAuthorize
  14550. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14554. // MaxEnergyOnInvalidId
  14555. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14559. // MeterValuesAlignedData
  14560. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14563. 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" );
  14564. else
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14567. // MeterValuesAlignedDataMaxLength
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14572. else
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14575. // MeterValuesSampledData
  14576. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14579. 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" );
  14580. else
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14583. // MeterValuesSampledDataMaxLength
  14584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14588. else
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14591. // MeterValueSampleInterval
  14592. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14596. // MinimumStatusDuration
  14597. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14600. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14602. // NumberOfConnectors
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14606. {
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14608. }
  14609. else
  14610. {
  14611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14612. }
  14613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14614. // ResetRetries
  14615. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14619. // ConnectorPhaseRotation
  14620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14624. // ConnectorPhaseRotationMaxLength
  14625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14629. // StopTransactionOnEVSideDisconnect
  14630. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14634. // StopTransactionOnInvalidId
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14639. // StopTxnAlignedData
  14640. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14644. // StopTxnAlignedDataMaxLength
  14645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14649. // StopTxnSampledData
  14650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14654. else
  14655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14657. // StopTxnSampledDataMaxLength
  14658. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14661. {
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14663. }
  14664. else
  14665. {
  14666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14667. }
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14669. // SupportedFeatureProfiles
  14670. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14674. // SupportedFeatureProfilesMaxLength
  14675. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14679. // TransactionMessageAttempts
  14680. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14683. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14685. // TransactionMessageRetryInterval
  14686. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14689. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14691. // UnlockConnectorOnEVSideDisconnect
  14692. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14696. // WebSocketPingInterval
  14697. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14701. // QueueOffLineMeterValues
  14702. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14706. // AuthorizationKey
  14707. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14711. // SecurityProfile
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14716. // DefaultPrice
  14717. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14721. // CustomDisplayCostAndPrice
  14722. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14726. // CustomIdleFeeAfterStop
  14727. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14731. // TimeOffset
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14736. // NextTimeOffsetTransitionDateTime
  14737. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14741. // TimeOffsetNextTransition
  14742. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14746. // SystemUptimeSec
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14751. // FreeVend
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14756. // FreeVendIdtag
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14761. // OcppServer
  14762. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14764. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14766. // MaintainServer
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14769. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14771. // StatusNotificationPeriodically
  14772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14776. // StatusNotificationInterval
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14781. // PreAuthAmount
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14786. // isEnableLocalPowerSharing
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14791. // PowerSharingServerIP
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14794. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14796. // EVCCID_PREFIX
  14797. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14801. // OffLineMaxChargingPower
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14806. // Configuration Version
  14807. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14811. // Charging profile refresh interval
  14812. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  14815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14816. //* Local Auth List Management Profile*/
  14817. #if 0
  14818. //For OCTT Test Case
  14819. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14822. #endif
  14823. #if 1
  14824. //LocalAuthListEnabled
  14825. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14829. #endif
  14830. //LocalAuthListMaxLength
  14831. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14835. //SendLocalListMaxLength
  14836. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14840. //ReserveConnectorZeroSupported
  14841. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14845. //* Smart Charging Profile */
  14846. //ChargeProfileMaxStackLevel
  14847. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14851. // ChargingScheduleAllowedChargingRateUnit
  14852. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14856. // ChargingScheduleMaxPeriods
  14857. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14861. // ConnectorSwitch3to1PhaseSupported
  14862. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14866. // MaxChargingProfilesInstalled
  14867. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14871. fclose(outfile);
  14872. }
  14873. else
  14874. {
  14875. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14876. char keystr[60]={0};
  14877. char readonlystr[10]={0};
  14878. char valuestr[256]={0};
  14879. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14880. if(fp == NULL) {
  14881. DEBUG_INFO("Error opening file");
  14882. return FALSE;
  14883. }
  14884. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14885. {
  14886. //DEBUG_INFO("Get Configuration \n");
  14887. if(strlen(str) > 0)
  14888. {
  14889. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14890. //*************************key*********************************/
  14891. if(strstr(str, "key") != NULL)
  14892. {
  14893. loc = strstr(str, "key");
  14894. c = 0;
  14895. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14896. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14897. {
  14898. sstr[c] = loc[strlen("key")+3+c];
  14899. c++;
  14900. }
  14901. sstr[c] = '\0';
  14902. strcpy(keystr,sstr);
  14903. }
  14904. //*************************readonly*********************************/
  14905. if(strstr(str, "readonly") != NULL)
  14906. {
  14907. loc = strstr(str, "readonly");
  14908. c = 0;
  14909. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14910. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14911. {
  14912. sstr[c] = loc[strlen("readonly")+2+c];
  14913. c++;
  14914. }
  14915. sstr[c] = '\0';
  14916. strcpy(readonlystr,sstr);
  14917. }
  14918. //*************************value*********************************/
  14919. if(strstr(str, "value") != NULL)
  14920. {
  14921. loc = strstr(str, "value");
  14922. c = 0;
  14923. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14924. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14925. {
  14926. sstr[c] = loc[strlen("value")+3+c];
  14927. c++;
  14928. }
  14929. sstr[c] = '\0';
  14930. strcpy(valuestr,sstr);
  14931. }
  14932. // DEBUG_INFO("keystr=%s\n",keystr);
  14933. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14934. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14935. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14936. {
  14937. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14938. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14940. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14941. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14942. }
  14943. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14944. {
  14945. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14946. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14948. }
  14949. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14950. {
  14951. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14953. }
  14954. if(strcmp(keystr, "BlinkRepeat") == 0)
  14955. {
  14956. //Charger.BlinkRepeat = Integer.parseInt(value);
  14957. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14959. }
  14960. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14961. {
  14962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14964. }
  14965. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14966. {
  14967. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14969. }
  14970. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14971. {
  14972. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14974. }
  14975. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14976. {
  14977. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14979. HeartBeatWaitTime = atoi(valuestr);
  14980. }
  14981. if(strcmp(keystr, "LightIntensity") == 0)
  14982. {
  14983. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14985. }
  14986. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14987. {
  14988. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14990. }
  14991. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14992. {
  14993. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14995. }
  14996. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14997. {
  14998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  15000. }
  15001. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  15002. {
  15003. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  15005. }
  15006. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  15007. {
  15008. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15010. }
  15011. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15012. {
  15013. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15015. }
  15016. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15017. {
  15018. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15020. }
  15021. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15022. {
  15023. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15025. }
  15026. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15027. {
  15028. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15030. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15031. }
  15032. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15033. {
  15034. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15036. }
  15037. if(strcmp(keystr, "ResetRetries") == 0)
  15038. {
  15039. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15041. }
  15042. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15043. {
  15044. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15046. }
  15047. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15048. {
  15049. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15051. }
  15052. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15053. {
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15056. }
  15057. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15058. {
  15059. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15061. }
  15062. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15063. {
  15064. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15066. }
  15067. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15068. {
  15069. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15071. }
  15072. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15073. {
  15074. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15076. }
  15077. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15078. {
  15079. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15081. }
  15082. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15083. {
  15084. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15086. }
  15087. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15088. {
  15089. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15091. }
  15092. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15093. {
  15094. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15096. TransactionMessageAttemptsValue = atoi(valuestr);
  15097. }
  15098. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15099. {
  15100. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15102. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15103. }
  15104. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15105. {
  15106. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15108. }
  15109. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15110. {
  15111. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15113. }
  15114. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15115. {
  15116. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15118. }
  15119. if(strcmp(keystr, "AuthorizationKey") == 0)
  15120. {
  15121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15122. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15124. }
  15125. if(strcmp(keystr, "SecurityProfile") == 0)
  15126. {
  15127. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15129. }
  15130. if(strcmp(keystr, "DefaultPrice") == 0)
  15131. {
  15132. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15134. }
  15135. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15136. {
  15137. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15139. }
  15140. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15141. {
  15142. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15144. }
  15145. if(strcmp(keystr, "TimeOffset") == 0)
  15146. {
  15147. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15149. }
  15150. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15151. {
  15152. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15154. }
  15155. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15156. {
  15157. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15159. }
  15160. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15161. {
  15162. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15164. }
  15165. if(strcmp(keystr, "FreeVend") == 0)
  15166. {
  15167. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15169. }
  15170. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15171. {
  15172. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15174. }
  15175. if(strcmp(keystr, "OcppServer") == 0)
  15176. {
  15177. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15178. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15179. }
  15180. if(strcmp(keystr, "MaintainServer") == 0)
  15181. {
  15182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15183. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15184. }
  15185. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15186. {
  15187. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15189. }
  15190. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15191. {
  15192. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15194. }
  15195. if(strcmp(keystr, "PreAuthAmount") == 0)
  15196. {
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15199. }
  15200. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15201. {
  15202. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15204. }
  15205. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15206. {
  15207. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15208. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15209. }
  15210. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15211. {
  15212. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15214. }
  15215. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15216. {
  15217. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15219. }
  15220. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15221. {
  15222. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15224. }
  15225. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  15226. {
  15227. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  15229. }
  15230. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15231. {
  15232. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15234. }
  15235. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15236. {
  15237. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15239. }
  15240. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15241. {
  15242. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15244. }
  15245. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15246. {
  15247. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15249. }
  15250. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15251. {
  15252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15254. }
  15255. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15256. {
  15257. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15259. }
  15260. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15261. {
  15262. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15264. }
  15265. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15266. {
  15267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15269. }
  15270. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15271. {
  15272. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15274. }
  15275. }
  15276. }
  15277. fclose(fp);
  15278. }
  15279. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15280. {
  15281. return PASS;
  15282. }
  15283. else
  15284. {
  15285. return FAIL;
  15286. }
  15287. }
  15288. void StoreConfigurationTable(void)
  15289. {
  15290. FILE *outfile;
  15291. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15292. if(outfile == NULL)
  15293. {
  15294. DEBUG_INFO("Error opening file");
  15295. return ;
  15296. }
  15297. /*Core Profile*/
  15298. //AllowOfflineTxForUnknownId
  15299. /*
  15300. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15301. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15304. */
  15305. //DEBUG_INFO("data=%s\n",data);
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15307. //AuthorizationCacheEnabled
  15308. /*
  15309. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15312. */
  15313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15314. //AuthorizeRemoteTxRequests
  15315. /*
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15319. */
  15320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15321. //BlinkRepeat
  15322. /*
  15323. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15326. */
  15327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15328. //ClockAlignedDataInterval
  15329. /*
  15330. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15333. */
  15334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15335. //ConnectionTimeOut
  15336. /*
  15337. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15340. */
  15341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15342. //GetConfigurationMaxKeys
  15343. /*
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15347. */
  15348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15349. // HeartbeatInterval
  15350. /*
  15351. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15354. */
  15355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15356. // LightIntensity
  15357. /*
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15361. */
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15363. // LocalAuthorizeOffline
  15364. /*
  15365. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15368. */
  15369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15370. // LocalPreAuthorize
  15371. /*
  15372. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15375. */
  15376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15377. // MaxEnergyOnInvalidId
  15378. /*
  15379. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15382. */
  15383. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15385. // MeterValuesAlignedData
  15386. /*
  15387. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15390. */
  15391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15392. // MeterValuesAlignedDataMaxLength
  15393. /*
  15394. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15397. */
  15398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15399. // MeterValuesSampledData
  15400. /*
  15401. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15404. */
  15405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15406. // MeterValuesSampledDataMaxLength
  15407. /*
  15408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15411. */
  15412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15413. // MeterValueSampleInterval
  15414. /*
  15415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15418. */
  15419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15420. // MinimumStatusDuration
  15421. /*
  15422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15425. */
  15426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15427. // NumberOfConnectors
  15428. /*
  15429. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15432. {
  15433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15434. }
  15435. else
  15436. {
  15437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15438. }
  15439. */
  15440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15441. // ResetRetries
  15442. /*
  15443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15446. */
  15447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15448. // ConnectorPhaseRotation
  15449. /*
  15450. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15453. */
  15454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15455. // ConnectorPhaseRotationMaxLength
  15456. /*
  15457. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15460. */
  15461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15462. // StopTransactionOnEVSideDisconnect
  15463. /*
  15464. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15467. */
  15468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15469. // StopTransactionOnInvalidId
  15470. /*
  15471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15474. */
  15475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15476. // StopTxnAlignedData
  15477. /*
  15478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15481. */
  15482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15483. // StopTxnAlignedDataMaxLength
  15484. /*
  15485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15488. */
  15489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15490. // StopTxnSampledData
  15491. /*
  15492. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15495. */
  15496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15497. // StopTxnSampledDataMaxLength
  15498. /*
  15499. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15502. */
  15503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15504. // SupportedFeatureProfiles
  15505. /*
  15506. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15509. */
  15510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15511. // SupportedFeatureProfilesMaxLength
  15512. /*
  15513. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15516. */
  15517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15518. // TransactionMessageAttempts
  15519. /*
  15520. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15523. */
  15524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15525. // TransactionMessageRetryInterval
  15526. /*
  15527. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15530. */
  15531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15532. // UnlockConnectorOnEVSideDisconnect
  15533. /*
  15534. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15537. */
  15538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15539. // WebSocketPingInterval
  15540. /*
  15541. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15544. */
  15545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15546. // QueueOffLineMeterValues
  15547. /*
  15548. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15551. */
  15552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15553. // AuthorizationKey
  15554. /*
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15558. */
  15559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15560. // SecurityProfile
  15561. /*
  15562. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15565. */
  15566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15567. // DefaultPrice
  15568. /*
  15569. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15572. */
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15574. // CustomDisplayCostAndPrice
  15575. /*
  15576. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15579. */
  15580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15581. // CustomIdleFeeAfterStop
  15582. /*
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15586. */
  15587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15588. // TimeOffset
  15589. /*
  15590. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15593. */
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15595. // NextTimeOffsetTransitionDateTime
  15596. /*
  15597. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15600. */
  15601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15602. // TimeOffsetNextTransition
  15603. /*
  15604. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15607. */
  15608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15609. // SystemUptimeSec
  15610. /*
  15611. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15614. */
  15615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15616. // FreeVend
  15617. /*
  15618. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15621. */
  15622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15623. // FreeVendIdtag
  15624. /*
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15628. */
  15629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15630. // OcppServer
  15631. /*
  15632. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15635. */
  15636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15637. // MaintainServer
  15638. /*
  15639. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15642. */
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15644. // StatusNotificationPeriodically
  15645. /*
  15646. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15649. */
  15650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15651. // StatusNotificationInterval
  15652. /*
  15653. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15656. */
  15657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15658. // PreAuthAmount
  15659. /*
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15663. */
  15664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15665. // isEnableLocalPowerSharing
  15666. /*
  15667. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15670. */
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15672. // PowerSharingServerIP
  15673. /*
  15674. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15677. */
  15678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15679. // EVCCID_PREFIX
  15680. /*
  15681. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15684. */
  15685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15686. // OffLineMaxChargingPower
  15687. /*
  15688. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15691. */
  15692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15693. // ConfigurationVersion
  15694. /*
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15698. */
  15699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15700. // CharingProfileRefreshInterval
  15701. /*
  15702. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  15705. */
  15706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15707. //* Local Auth List Management Profile*/
  15708. //LocalAuthListEnabled
  15709. /*
  15710. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15713. */
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15715. //LocalAuthListMaxLength
  15716. /*
  15717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15720. */
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15722. //SendLocalListMaxLength
  15723. /*
  15724. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15727. */
  15728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15729. //ReserveConnectorZeroSupported
  15730. /*
  15731. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15734. */
  15735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15736. //* Smart Charging Profile */
  15737. //ChargeProfileMaxStackLevel
  15738. /*
  15739. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15742. */
  15743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15744. // ChargingScheduleAllowedChargingRateUnit
  15745. /*
  15746. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15749. */
  15750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15751. // ChargingScheduleMaxPeriods
  15752. /*
  15753. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15756. */
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15758. // ConnectorSwitch3to1PhaseSupported
  15759. /*
  15760. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15763. */
  15764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15765. // MaxChargingProfilesInstalled
  15766. /*
  15767. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15770. */
  15771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15772. fclose(outfile);
  15773. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15774. }
  15775. void getKeyValue(char *keyReq)
  15776. {
  15777. int isEmpty = FALSE;
  15778. int isKnowKey = FALSE;
  15779. DEBUG_INFO("keyReq = %s\n", keyReq);
  15780. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15781. isEmpty = TRUE;
  15782. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15783. {
  15784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15787. {
  15788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15789. }
  15790. else
  15791. {
  15792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15793. }
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15795. isKnowKey = TRUE;
  15796. }
  15797. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15798. {
  15799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15802. {
  15803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15804. }
  15805. else
  15806. {
  15807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15808. }
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15810. isKnowKey = TRUE;
  15811. }
  15812. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15813. {
  15814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15817. {
  15818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15819. }
  15820. else
  15821. {
  15822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15823. }
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15825. isKnowKey = TRUE;
  15826. }
  15827. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15828. {
  15829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15832. {
  15833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15834. }
  15835. else
  15836. {
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15838. }
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15840. isKnowKey = TRUE;
  15841. }
  15842. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15843. {
  15844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15847. {
  15848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15849. }
  15850. else
  15851. {
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15853. }
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15855. isKnowKey = TRUE;
  15856. }
  15857. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15858. {
  15859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15862. {
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15864. }
  15865. else
  15866. {
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15868. }
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15870. isKnowKey = TRUE;
  15871. }
  15872. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15873. {
  15874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15877. {
  15878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15879. }
  15880. else
  15881. {
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15883. }
  15884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15885. isKnowKey = TRUE;
  15886. }
  15887. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15888. {
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15892. {
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15894. }
  15895. else
  15896. {
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15898. }
  15899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15900. isKnowKey = TRUE;
  15901. }
  15902. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15907. {
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15909. }
  15910. else
  15911. {
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15913. }
  15914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15915. isKnowKey = TRUE;
  15916. }
  15917. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15918. {
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15922. {
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15924. }
  15925. else
  15926. {
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15928. }
  15929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15930. isKnowKey = TRUE;
  15931. }
  15932. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15933. {
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15937. {
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15939. }
  15940. else
  15941. {
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15943. }
  15944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15945. isKnowKey = TRUE;
  15946. }
  15947. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15948. {
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15952. {
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15954. }
  15955. else
  15956. {
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15958. }
  15959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15960. isKnowKey = TRUE;
  15961. }
  15962. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15963. {
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15967. {
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15969. }
  15970. else
  15971. {
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15973. }
  15974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15975. isKnowKey = TRUE;
  15976. }
  15977. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15978. {
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15982. {
  15983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15984. }
  15985. else
  15986. {
  15987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15988. }
  15989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15990. isKnowKey = TRUE;
  15991. }
  15992. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15993. {
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15997. {
  15998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15999. }
  16000. else
  16001. {
  16002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  16003. }
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  16005. isKnowKey = TRUE;
  16006. }
  16007. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  16008. {
  16009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  16010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  16011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16012. {
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16014. }
  16015. else
  16016. {
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16018. }
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16020. isKnowKey = TRUE;
  16021. }
  16022. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16023. {
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16027. {
  16028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16029. }
  16030. else
  16031. {
  16032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16033. }
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16035. isKnowKey = TRUE;
  16036. }
  16037. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16038. {
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16042. {
  16043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16044. }
  16045. else
  16046. {
  16047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16048. }
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16050. isKnowKey = TRUE;
  16051. }
  16052. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16053. {
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16057. {
  16058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16059. }
  16060. else
  16061. {
  16062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16063. }
  16064. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16066. isKnowKey = TRUE;
  16067. }
  16068. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16069. {
  16070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16073. {
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16075. }
  16076. else
  16077. {
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16079. }
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16081. isKnowKey = TRUE;
  16082. }
  16083. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16084. {
  16085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16088. {
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16090. }
  16091. else
  16092. {
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16094. }
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16096. isKnowKey = TRUE;
  16097. }
  16098. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16099. {
  16100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16103. {
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16105. }
  16106. else
  16107. {
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16109. }
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16111. isKnowKey = TRUE;
  16112. }
  16113. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16114. {
  16115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16118. {
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16120. }
  16121. else
  16122. {
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16124. }
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16126. isKnowKey = TRUE;
  16127. }
  16128. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16129. {
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16133. {
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16135. }
  16136. else
  16137. {
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16139. }
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16141. isKnowKey = TRUE;
  16142. }
  16143. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16144. {
  16145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16148. {
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16150. }
  16151. else
  16152. {
  16153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16154. }
  16155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16156. isKnowKey = TRUE;
  16157. }
  16158. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16159. {
  16160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16163. {
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16165. }
  16166. else
  16167. {
  16168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16169. }
  16170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16171. isKnowKey = TRUE;
  16172. }
  16173. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16174. {
  16175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16178. {
  16179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16180. }
  16181. else
  16182. {
  16183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16184. }
  16185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16186. isKnowKey = TRUE;
  16187. }
  16188. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16189. {
  16190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16193. {
  16194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16195. }
  16196. else
  16197. {
  16198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16199. }
  16200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16201. isKnowKey = TRUE;
  16202. }
  16203. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16204. {
  16205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16208. {
  16209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16210. }
  16211. else
  16212. {
  16213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16214. }
  16215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16216. isKnowKey = TRUE;
  16217. }
  16218. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16219. {
  16220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16223. {
  16224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16225. }
  16226. else
  16227. {
  16228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16229. }
  16230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16231. isKnowKey = TRUE;
  16232. }
  16233. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16234. {
  16235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16238. {
  16239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16240. }
  16241. else
  16242. {
  16243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16244. }
  16245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16246. isKnowKey = TRUE;
  16247. }
  16248. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16249. {
  16250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16253. {
  16254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16255. }
  16256. else
  16257. {
  16258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16259. }
  16260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16261. isKnowKey = TRUE;
  16262. }
  16263. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16264. {
  16265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16268. {
  16269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16270. }
  16271. else
  16272. {
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16274. }
  16275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16276. isKnowKey = TRUE;
  16277. }
  16278. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16279. {
  16280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16283. {
  16284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16285. }
  16286. else
  16287. {
  16288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16289. }
  16290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16291. isKnowKey = TRUE;
  16292. }
  16293. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16294. {
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16298. {
  16299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16300. }
  16301. else
  16302. {
  16303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16304. }
  16305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16306. isKnowKey = TRUE;
  16307. }
  16308. /*
  16309. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16310. {
  16311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16314. {
  16315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16316. }
  16317. else
  16318. {
  16319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16320. }
  16321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16322. isKnowKey = TRUE;
  16323. }*/
  16324. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16325. {
  16326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16329. {
  16330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16331. }
  16332. else
  16333. {
  16334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16335. }
  16336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16337. isKnowKey = TRUE;
  16338. }
  16339. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16340. {
  16341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16344. {
  16345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16346. }
  16347. else
  16348. {
  16349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16350. }
  16351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16352. isKnowKey = TRUE;
  16353. }
  16354. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16355. {
  16356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16359. {
  16360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16361. }
  16362. else
  16363. {
  16364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16365. }
  16366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16367. isKnowKey = TRUE;
  16368. }
  16369. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16370. {
  16371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16374. {
  16375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16376. }
  16377. else
  16378. {
  16379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16380. }
  16381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16382. isKnowKey = TRUE;
  16383. }
  16384. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16385. {
  16386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16389. {
  16390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16391. }
  16392. else
  16393. {
  16394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16395. }
  16396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16397. isKnowKey = TRUE;
  16398. }
  16399. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16400. {
  16401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16404. {
  16405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16406. }
  16407. else
  16408. {
  16409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16410. }
  16411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16412. isKnowKey = TRUE;
  16413. }
  16414. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16415. {
  16416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16419. {
  16420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16421. }
  16422. else
  16423. {
  16424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16425. }
  16426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16427. isKnowKey = TRUE;
  16428. }
  16429. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16430. {
  16431. struct sysinfo s_info;
  16432. int error = sysinfo(&s_info);
  16433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16436. {
  16437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16438. }
  16439. else
  16440. {
  16441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16442. }
  16443. if(error != 0)
  16444. {
  16445. DEBUG_WARN("System uptime get error: %d\n", error);
  16446. }
  16447. else
  16448. {
  16449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16450. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16451. }
  16452. isKnowKey = TRUE;
  16453. }
  16454. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16455. {
  16456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16459. {
  16460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16461. }
  16462. else
  16463. {
  16464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16465. }
  16466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16467. isKnowKey = TRUE;
  16468. }
  16469. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16470. {
  16471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16474. {
  16475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16476. }
  16477. else
  16478. {
  16479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16480. }
  16481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16482. isKnowKey = TRUE;
  16483. }
  16484. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16485. {
  16486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16489. {
  16490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16491. }
  16492. else
  16493. {
  16494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16495. }
  16496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16497. isKnowKey = TRUE;
  16498. }
  16499. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16500. {
  16501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16504. {
  16505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16506. }
  16507. else
  16508. {
  16509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16510. }
  16511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16512. isKnowKey = TRUE;
  16513. }
  16514. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16515. {
  16516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16519. {
  16520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16521. }
  16522. else
  16523. {
  16524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16525. }
  16526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16527. isKnowKey = TRUE;
  16528. }
  16529. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16530. {
  16531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16534. {
  16535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16536. }
  16537. else
  16538. {
  16539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16540. }
  16541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16542. isKnowKey = TRUE;
  16543. }
  16544. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16545. {
  16546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16549. {
  16550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16551. }
  16552. else
  16553. {
  16554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16555. }
  16556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16557. isKnowKey = TRUE;
  16558. }
  16559. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16560. {
  16561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16564. {
  16565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16566. }
  16567. else
  16568. {
  16569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16570. }
  16571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16572. isKnowKey = TRUE;
  16573. }
  16574. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16575. {
  16576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16579. {
  16580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16581. }
  16582. else
  16583. {
  16584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16585. }
  16586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16587. isKnowKey = TRUE;
  16588. }
  16589. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16590. {
  16591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16594. {
  16595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16596. }
  16597. else
  16598. {
  16599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16600. }
  16601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16602. isKnowKey = TRUE;
  16603. }
  16604. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16605. {
  16606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16609. {
  16610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16611. }
  16612. else
  16613. {
  16614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16615. }
  16616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16617. isKnowKey = TRUE;
  16618. }
  16619. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16620. {
  16621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16624. {
  16625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16626. }
  16627. else
  16628. {
  16629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16630. }
  16631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16632. isKnowKey = TRUE;
  16633. }
  16634. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  16635. {
  16636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  16637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  16638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16639. {
  16640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  16641. }
  16642. else
  16643. {
  16644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  16645. }
  16646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  16647. isKnowKey = TRUE;
  16648. }
  16649. #if 1
  16650. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16651. {
  16652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16654. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16655. {
  16656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16657. }
  16658. else
  16659. {
  16660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16661. }
  16662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16663. isKnowKey = TRUE;
  16664. }
  16665. #endif
  16666. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16667. {
  16668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16670. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16671. {
  16672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16673. }
  16674. else
  16675. {
  16676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16677. }
  16678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16679. isKnowKey = TRUE;
  16680. }
  16681. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16682. {
  16683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16685. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16686. {
  16687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16688. }
  16689. else
  16690. {
  16691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16692. }
  16693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16694. isKnowKey = TRUE;
  16695. }
  16696. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16697. {
  16698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16700. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16701. {
  16702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16703. }
  16704. else
  16705. {
  16706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16707. }
  16708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16709. isKnowKey = TRUE;
  16710. }
  16711. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16712. {
  16713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16715. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16716. {
  16717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16718. }
  16719. else
  16720. {
  16721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16722. }
  16723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16724. isKnowKey = TRUE;
  16725. }
  16726. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16727. {
  16728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16730. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16731. {
  16732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16733. }
  16734. else
  16735. {
  16736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16737. }
  16738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16739. isKnowKey = TRUE;
  16740. }
  16741. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16742. {
  16743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16745. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16746. {
  16747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16748. }
  16749. else
  16750. {
  16751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16752. }
  16753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16754. isKnowKey = TRUE;
  16755. }
  16756. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16757. {
  16758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16761. {
  16762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16763. }
  16764. else
  16765. {
  16766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16767. }
  16768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16769. isKnowKey = TRUE;
  16770. }
  16771. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16772. {
  16773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16775. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16776. {
  16777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16778. }
  16779. else
  16780. {
  16781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16782. }
  16783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16784. isKnowKey = TRUE;
  16785. }
  16786. //=========================================================
  16787. if(!isEmpty && !isKnowKey)
  16788. {
  16789. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16790. strcpy(unknownkey[UnknownKeynum], keyReq);
  16791. UnknownKeynum = UnknownKeynum + 1;
  16792. }
  16793. }
  16794. void processUnkownKey(void)
  16795. {
  16796. DEBUG_INFO("processUnkownKey...\n");
  16797. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16798. for(int index=0; index < UnknownKeynum; index++)
  16799. {
  16800. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16801. {
  16802. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16803. }
  16804. }
  16805. }
  16806. int setKeyValue(char *key, char *value)
  16807. {
  16808. int isSuccess = NotSupported;
  16809. int check_ascii=0;
  16810. char str[501]={0};
  16811. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16812. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16813. {
  16814. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16816. {
  16817. strcpy(str, (const char*)value);
  16818. for(int i = 0; str[i]; i++){
  16819. str[i] = tolower(str[i]);
  16820. }
  16821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16822. isSuccess = ConfigurationStatus_Accepted;
  16823. }
  16824. else
  16825. {
  16826. isSuccess = ConfigurationStatus_Rejected;
  16827. }
  16828. }
  16829. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16830. {
  16831. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16833. {
  16834. strcpy(str, (const char*)value);
  16835. for(int i = 0; str[i]; i++){
  16836. str[i] = tolower(str[i]);
  16837. }
  16838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16839. isSuccess = ConfigurationStatus_Accepted;
  16840. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16841. }
  16842. else
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. }
  16847. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16848. {
  16849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16850. {
  16851. strcpy(str, (const char*)value);
  16852. for(int i = 0; str[i]; i++)
  16853. {
  16854. str[i] = tolower(str[i]);
  16855. }
  16856. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16858. isSuccess = ConfigurationStatus_Accepted;
  16859. }
  16860. else
  16861. {
  16862. isSuccess = ConfigurationStatus_Rejected;
  16863. }
  16864. }
  16865. if(strcmp(key, "BlinkRepeat") == 0)
  16866. {
  16867. //Charger.BlinkRepeat = Integer.parseInt(value);
  16868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16869. {
  16870. check_ascii = value[0];
  16871. if( (check_ascii < 48) || (check_ascii > 57) )
  16872. {
  16873. isSuccess = ConfigurationStatus_Rejected;
  16874. }
  16875. else
  16876. {
  16877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16878. isSuccess = ConfigurationStatus_Accepted;
  16879. }
  16880. }
  16881. else
  16882. {
  16883. isSuccess = ConfigurationStatus_Rejected;
  16884. }
  16885. }
  16886. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16887. {
  16888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16889. {
  16890. check_ascii = value[0];
  16891. if( (check_ascii < 48) || (check_ascii > 57) )
  16892. {
  16893. isSuccess = ConfigurationStatus_Rejected;
  16894. }
  16895. else
  16896. {
  16897. if((atoi(value) == 0) || (atoi(value) >= 5))
  16898. {
  16899. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16901. isSuccess = ConfigurationStatus_Accepted;
  16902. }
  16903. else
  16904. isSuccess = ConfigurationStatus_Rejected;
  16905. }
  16906. }
  16907. else
  16908. {
  16909. isSuccess = ConfigurationStatus_Rejected;
  16910. }
  16911. }
  16912. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16913. {
  16914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16915. {
  16916. check_ascii = value[0];
  16917. if( (check_ascii < 48) || (check_ascii > 57) )
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. else
  16922. {
  16923. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. }
  16928. else
  16929. {
  16930. isSuccess = ConfigurationStatus_Rejected;
  16931. }
  16932. }
  16933. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16934. {
  16935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16936. {
  16937. check_ascii = value[0];
  16938. if( (check_ascii < 48) || (check_ascii > 57) )
  16939. {
  16940. isSuccess = ConfigurationStatus_Rejected;
  16941. }
  16942. else
  16943. {
  16944. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16946. isSuccess = ConfigurationStatus_Accepted;
  16947. }
  16948. }
  16949. else
  16950. {
  16951. isSuccess = ConfigurationStatus_Rejected;
  16952. }
  16953. }
  16954. if(strcmp(key, "HeartbeatInterval") == 0)
  16955. {
  16956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16957. {
  16958. check_ascii = value[0];
  16959. if( (check_ascii < 48) || (check_ascii > 57) )
  16960. {
  16961. isSuccess = ConfigurationStatus_Rejected;
  16962. }
  16963. else
  16964. {
  16965. if((atoi(value) == 0) || (atoi(value) >= 10))
  16966. {
  16967. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16969. HeartBeatWaitTime = atoi(value);
  16970. isSuccess = ConfigurationStatus_Accepted;
  16971. }
  16972. else
  16973. {
  16974. isSuccess = ConfigurationStatus_Rejected;
  16975. }
  16976. }
  16977. }
  16978. else
  16979. {
  16980. isSuccess = ConfigurationStatus_Rejected;
  16981. }
  16982. }
  16983. if(strcmp(key, "LightIntensity") == 0)
  16984. {
  16985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16986. {
  16987. check_ascii = value[0];
  16988. if( (check_ascii < 48) || (check_ascii > 57) )
  16989. {
  16990. isSuccess = ConfigurationStatus_Rejected;
  16991. }
  16992. else
  16993. {
  16994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16995. isSuccess = ConfigurationStatus_Accepted;
  16996. }
  16997. }
  16998. else
  16999. {
  17000. isSuccess = ConfigurationStatus_Rejected;
  17001. }
  17002. }
  17003. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  17004. {
  17005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17006. {
  17007. strcpy(str, (const char*)value);
  17008. for(int i = 0; str[i]; i++)
  17009. {
  17010. str[i] = tolower(str[i]);
  17011. }
  17012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17013. isSuccess = ConfigurationStatus_Accepted;
  17014. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  17015. }
  17016. else
  17017. {
  17018. isSuccess = ConfigurationStatus_Rejected;
  17019. }
  17020. }
  17021. if(strcmp(key, "LocalPreAuthorize") == 0)
  17022. {
  17023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17024. {
  17025. strcpy(str, (const char*)value);
  17026. for(int i = 0; str[i]; i++)
  17027. {
  17028. str[i] = tolower(str[i]);
  17029. }
  17030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17031. isSuccess = ConfigurationStatus_Accepted;
  17032. }
  17033. else
  17034. {
  17035. isSuccess = ConfigurationStatus_Rejected;
  17036. }
  17037. }
  17038. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17039. {
  17040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17041. {
  17042. check_ascii = value[0];
  17043. if( (check_ascii < 48) || (check_ascii > 57) )
  17044. {
  17045. isSuccess = ConfigurationStatus_Rejected;
  17046. }
  17047. else
  17048. {
  17049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17050. isSuccess = ConfigurationStatus_Accepted;
  17051. }
  17052. }
  17053. else
  17054. {
  17055. isSuccess = ConfigurationStatus_Rejected;
  17056. }
  17057. }
  17058. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17059. {
  17060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17061. {
  17062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17063. isSuccess = ConfigurationStatus_Accepted;
  17064. }
  17065. else
  17066. {
  17067. isSuccess = ConfigurationStatus_Rejected;
  17068. }
  17069. }
  17070. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17071. {
  17072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17073. {
  17074. check_ascii = value[0];
  17075. if( (check_ascii < 48) || (check_ascii > 57) )
  17076. {
  17077. isSuccess = ConfigurationStatus_Rejected;
  17078. }
  17079. else
  17080. {
  17081. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17083. isSuccess = ConfigurationStatus_Accepted;
  17084. }
  17085. }
  17086. else
  17087. {
  17088. isSuccess = ConfigurationStatus_Rejected;
  17089. }
  17090. }
  17091. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17092. {
  17093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17094. {
  17095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17096. isSuccess = ConfigurationStatus_Accepted;
  17097. }
  17098. else
  17099. {
  17100. isSuccess = ConfigurationStatus_Rejected;
  17101. }
  17102. }
  17103. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17104. {
  17105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17106. {
  17107. check_ascii = value[0];
  17108. if( (check_ascii < 48) || (check_ascii > 57) )
  17109. {
  17110. isSuccess = ConfigurationStatus_Rejected;
  17111. }
  17112. else
  17113. {
  17114. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17116. isSuccess = ConfigurationStatus_Accepted;
  17117. }
  17118. }
  17119. else
  17120. {
  17121. isSuccess = ConfigurationStatus_Rejected;
  17122. }
  17123. }
  17124. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17125. {
  17126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17127. {
  17128. check_ascii = value[0];
  17129. if( (check_ascii < 48) || (check_ascii > 57) )
  17130. {
  17131. isSuccess = ConfigurationStatus_Rejected;
  17132. }
  17133. else
  17134. {
  17135. if((atoi(value) == 0) || (atoi(value) >= 3))
  17136. {
  17137. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17139. isSuccess = ConfigurationStatus_Accepted;
  17140. }
  17141. else
  17142. {
  17143. isSuccess = ConfigurationStatus_Rejected;
  17144. }
  17145. }
  17146. }
  17147. else
  17148. {
  17149. isSuccess = ConfigurationStatus_Rejected;
  17150. }
  17151. }
  17152. if(strcmp(key, "MinimumStatusDuration") == 0)
  17153. {
  17154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17155. {
  17156. check_ascii = value[0];
  17157. if( (check_ascii < 48) || (check_ascii > 57) )
  17158. {
  17159. isSuccess = ConfigurationStatus_Rejected;
  17160. }
  17161. else
  17162. {
  17163. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17164. {
  17165. isSuccess = ConfigurationStatus_Rejected;
  17166. }
  17167. else
  17168. {
  17169. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17171. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17172. isSuccess = ConfigurationStatus_Accepted;
  17173. }
  17174. }
  17175. }
  17176. else
  17177. {
  17178. isSuccess = ConfigurationStatus_Rejected;
  17179. }
  17180. }
  17181. if(strcmp(key, "NumberOfConnectors") == 0)
  17182. {
  17183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17184. {
  17185. check_ascii = value[0];
  17186. if( (check_ascii < 48) || (check_ascii > 57) )
  17187. {
  17188. isSuccess = ConfigurationStatus_Rejected;
  17189. }
  17190. else
  17191. {
  17192. //Charger.ResetRetries = Integer.parseInt(value);
  17193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17194. isSuccess = ConfigurationStatus_Accepted;
  17195. }
  17196. }
  17197. else
  17198. {
  17199. isSuccess = ConfigurationStatus_Rejected;
  17200. }
  17201. }
  17202. if(strcmp(key, "ResetRetries") == 0)
  17203. {
  17204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17205. {
  17206. check_ascii = value[0];
  17207. if( (check_ascii < 48) || (check_ascii > 57) )
  17208. {
  17209. isSuccess = ConfigurationStatus_Rejected;
  17210. }
  17211. else
  17212. {
  17213. //Charger.ResetRetries = Integer.parseInt(value);
  17214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17215. isSuccess = ConfigurationStatus_Accepted;
  17216. }
  17217. }
  17218. else
  17219. {
  17220. isSuccess = ConfigurationStatus_Rejected;
  17221. }
  17222. }
  17223. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17224. {
  17225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17226. {
  17227. strcpy(str, (const char*)value);
  17228. for(int i = 0; str[i]; i++)
  17229. {
  17230. str[i] = tolower(str[i]);
  17231. }
  17232. if(strcmp(str, "notapplicable")== 0)
  17233. {
  17234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17235. isSuccess = ConfigurationStatus_Accepted;
  17236. }
  17237. else if(strcmp(str, "unknown")== 0)
  17238. {
  17239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17240. isSuccess = ConfigurationStatus_Accepted;
  17241. }
  17242. else if(strcmp(str, "rst")== 0)
  17243. {
  17244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17245. isSuccess = ConfigurationStatus_Accepted;
  17246. }
  17247. else if(strcmp(str, "rts")== 0)
  17248. {
  17249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17250. isSuccess = ConfigurationStatus_Accepted;
  17251. }
  17252. else if(strcmp(str, "srt")== 0)
  17253. {
  17254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17255. isSuccess = ConfigurationStatus_Accepted;
  17256. }
  17257. else if(strcmp(str, "str")== 0)
  17258. {
  17259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17260. isSuccess = ConfigurationStatus_Accepted;
  17261. }
  17262. else if(strcmp(str, "trs")== 0)
  17263. {
  17264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17265. isSuccess = ConfigurationStatus_Accepted;
  17266. }
  17267. else if(strcmp(str, "tsr")== 0)
  17268. {
  17269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17270. isSuccess = ConfigurationStatus_Accepted;
  17271. }
  17272. else
  17273. {
  17274. isSuccess = ConfigurationStatus_Rejected;
  17275. }
  17276. }
  17277. else
  17278. {
  17279. isSuccess = ConfigurationStatus_Rejected;
  17280. }
  17281. }
  17282. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17283. {
  17284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17285. {
  17286. check_ascii = value[0];
  17287. if( (check_ascii < 48) || (check_ascii > 57) )
  17288. {
  17289. isSuccess = ConfigurationStatus_Rejected;
  17290. }
  17291. else
  17292. {
  17293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17294. isSuccess = ConfigurationStatus_Accepted;
  17295. }
  17296. }
  17297. else
  17298. {
  17299. isSuccess = ConfigurationStatus_Rejected;
  17300. }
  17301. }
  17302. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17303. {
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17305. {
  17306. strcpy(str, (const char*)value);
  17307. for(int i = 0; str[i]; i++)
  17308. {
  17309. str[i] = tolower(str[i]);
  17310. }
  17311. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17313. isSuccess = ConfigurationStatus_Accepted;
  17314. }
  17315. else
  17316. {
  17317. isSuccess = ConfigurationStatus_Rejected;
  17318. }
  17319. }
  17320. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17321. {
  17322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17323. {
  17324. strcpy(str, (const char*)value);
  17325. for(int i = 0; str[i]; i++)
  17326. {
  17327. str[i] = tolower(str[i]);
  17328. }
  17329. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17331. isSuccess = ConfigurationStatus_Accepted;
  17332. }
  17333. else
  17334. {
  17335. isSuccess = ConfigurationStatus_Rejected;
  17336. }
  17337. }
  17338. if(strcmp(key, "StopTxnAlignedData") == 0)
  17339. {
  17340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17341. {
  17342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17343. isSuccess = ConfigurationStatus_Accepted;
  17344. }
  17345. else
  17346. {
  17347. isSuccess = ConfigurationStatus_Rejected;
  17348. }
  17349. }
  17350. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17351. {
  17352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17353. {
  17354. check_ascii = value[0];
  17355. if( (check_ascii < 48) || (check_ascii > 57) )
  17356. {
  17357. isSuccess = ConfigurationStatus_Rejected;
  17358. }
  17359. else
  17360. {
  17361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17362. isSuccess = ConfigurationStatus_Accepted;
  17363. }
  17364. }
  17365. else
  17366. {
  17367. isSuccess = ConfigurationStatus_Rejected;
  17368. }
  17369. }
  17370. if(strcmp(key, "StopTxnSampledData") == 0)
  17371. {
  17372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17373. {
  17374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17375. isSuccess = ConfigurationStatus_Accepted;
  17376. }
  17377. else
  17378. {
  17379. isSuccess = ConfigurationStatus_Rejected;
  17380. }
  17381. }
  17382. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17383. {
  17384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17385. {
  17386. check_ascii = value[0];
  17387. if( (check_ascii < 48) || (check_ascii > 57) )
  17388. {
  17389. isSuccess = ConfigurationStatus_Rejected;
  17390. }
  17391. else
  17392. {
  17393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17394. isSuccess = ConfigurationStatus_Accepted;
  17395. }
  17396. }
  17397. else
  17398. {
  17399. isSuccess = ConfigurationStatus_Rejected;
  17400. }
  17401. }
  17402. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17403. {
  17404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17405. {
  17406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17407. isSuccess = ConfigurationStatus_Accepted;
  17408. }
  17409. else
  17410. {
  17411. isSuccess = ConfigurationStatus_Rejected;
  17412. }
  17413. }
  17414. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17415. {
  17416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17417. {
  17418. check_ascii = value[0];
  17419. if( (check_ascii < 48) || (check_ascii > 57) )
  17420. {
  17421. isSuccess = ConfigurationStatus_Rejected;
  17422. }
  17423. else
  17424. {
  17425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17426. isSuccess = ConfigurationStatus_Accepted;
  17427. }
  17428. }
  17429. else
  17430. {
  17431. isSuccess = ConfigurationStatus_Rejected;
  17432. }
  17433. }
  17434. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17435. {
  17436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17437. {
  17438. check_ascii = value[0];
  17439. if( (check_ascii < 48) || (check_ascii > 57) )
  17440. {
  17441. isSuccess = ConfigurationStatus_Rejected;
  17442. }
  17443. else
  17444. {
  17445. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17447. TransactionMessageAttemptsValue = atoi(value);
  17448. isSuccess = ConfigurationStatus_Accepted;
  17449. }
  17450. }
  17451. else
  17452. {
  17453. isSuccess = ConfigurationStatus_Rejected;
  17454. }
  17455. }
  17456. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17457. {
  17458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17459. {
  17460. check_ascii = value[0];
  17461. if( (check_ascii < 48) || (check_ascii > 57) )
  17462. {
  17463. isSuccess = ConfigurationStatus_Rejected;
  17464. }
  17465. else
  17466. {
  17467. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17469. TransactionMessageRetryIntervalValue = atoi(value);
  17470. isSuccess = ConfigurationStatus_Accepted;
  17471. }
  17472. }
  17473. else
  17474. {
  17475. isSuccess = ConfigurationStatus_Rejected;
  17476. }
  17477. }
  17478. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17479. {
  17480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17481. {
  17482. strcpy(str, (const char*)value);
  17483. for(int i = 0; str[i]; i++)
  17484. {
  17485. str[i] = tolower(str[i]);
  17486. }
  17487. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17489. isSuccess = ConfigurationStatus_Accepted;
  17490. }
  17491. else
  17492. {
  17493. isSuccess = ConfigurationStatus_Rejected;
  17494. }
  17495. }
  17496. if(strcmp(key, "WebSocketPingInterval") == 0)
  17497. {
  17498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17499. {
  17500. check_ascii = value[0];
  17501. if( (check_ascii < 48) || (check_ascii > 57) )
  17502. {
  17503. isSuccess = ConfigurationStatus_Rejected;
  17504. }
  17505. else
  17506. {
  17507. if((atoi(value) == 0) || (atoi(value) >= 10))
  17508. {
  17509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17510. isSuccess = ConfigurationStatus_Accepted;
  17511. }
  17512. else
  17513. isSuccess = ConfigurationStatus_Rejected;
  17514. }
  17515. }
  17516. else
  17517. {
  17518. isSuccess = ConfigurationStatus_Rejected;
  17519. }
  17520. }
  17521. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17522. {
  17523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17524. {
  17525. strcpy(str, (const char*)value);
  17526. for(int i = 0; str[i]; i++)
  17527. {
  17528. str[i] = tolower(str[i]);
  17529. }
  17530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17531. isSuccess = ConfigurationStatus_Accepted;
  17532. }
  17533. else
  17534. {
  17535. isSuccess = ConfigurationStatus_Rejected;
  17536. }
  17537. }
  17538. if(strcmp(key, "AuthorizationKey") == 0)
  17539. {
  17540. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17541. {
  17542. strcpy(str, (const char*)value);
  17543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17544. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17545. isSuccess = ConfigurationStatus_Accepted;
  17546. }
  17547. else
  17548. {
  17549. isSuccess = ConfigurationStatus_Rejected;
  17550. }
  17551. }
  17552. if(strcmp(key, "SecurityProfile") == 0)
  17553. {
  17554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17555. {
  17556. check_ascii = value[0];
  17557. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17558. {
  17559. isSuccess = ConfigurationStatus_Rejected;
  17560. }
  17561. else if(check_ascii == 0x33)
  17562. {
  17563. isSuccess = NotSupported;
  17564. }
  17565. else
  17566. {
  17567. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17568. {
  17569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17570. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17571. isSuccess = ConfigurationStatus_Accepted;
  17572. }
  17573. else
  17574. isSuccess = ConfigurationStatus_Rejected;
  17575. }
  17576. }
  17577. else
  17578. {
  17579. isSuccess = ConfigurationStatus_Rejected;
  17580. }
  17581. }
  17582. if(strcmp(key, "DefaultPrice") == 0)
  17583. {
  17584. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17585. {
  17586. strcpy(str, (const char*)value);
  17587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17588. isSuccess = ConfigurationStatus_Accepted;
  17589. }
  17590. else
  17591. {
  17592. isSuccess = ConfigurationStatus_Rejected;
  17593. }
  17594. }
  17595. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17596. {
  17597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17598. {
  17599. strcpy(str, (const char*)value);
  17600. for(int i = 0; str[i]; i++)
  17601. {
  17602. str[i] = tolower(str[i]);
  17603. }
  17604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17605. isSuccess = ConfigurationStatus_Accepted;
  17606. }
  17607. else
  17608. {
  17609. isSuccess = ConfigurationStatus_Rejected;
  17610. }
  17611. }
  17612. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17613. {
  17614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17615. {
  17616. strcpy(str, (const char*)value);
  17617. for(int i = 0; str[i]; i++)
  17618. {
  17619. str[i] = tolower(str[i]);
  17620. }
  17621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17622. isSuccess = ConfigurationStatus_Accepted;
  17623. }
  17624. else
  17625. {
  17626. isSuccess = ConfigurationStatus_Rejected;
  17627. }
  17628. }
  17629. if(strcmp(key, "TimeOffset") == 0)
  17630. {
  17631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17632. {
  17633. strcpy(str, (const char*)value);
  17634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17635. isSuccess = ConfigurationStatus_Accepted;
  17636. }
  17637. else
  17638. {
  17639. isSuccess = ConfigurationStatus_Rejected;
  17640. }
  17641. }
  17642. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17643. {
  17644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17645. {
  17646. strcpy(str, (const char*)value);
  17647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17648. isSuccess = ConfigurationStatus_Accepted;
  17649. }
  17650. else
  17651. {
  17652. isSuccess = ConfigurationStatus_Rejected;
  17653. }
  17654. }
  17655. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17656. {
  17657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17658. {
  17659. strcpy(str, (const char*)value);
  17660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17661. isSuccess = ConfigurationStatus_Accepted;
  17662. }
  17663. else
  17664. {
  17665. isSuccess = ConfigurationStatus_Rejected;
  17666. }
  17667. }
  17668. if(strcmp(key, "SystemUptimeSec") == 0)
  17669. {
  17670. isSuccess = NotSupported;
  17671. }
  17672. if(strcmp(key, "FreeVend") == 0)
  17673. {
  17674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17675. {
  17676. strcpy(str, (const char*)value);
  17677. for(int i = 0; str[i]; i++)
  17678. {
  17679. str[i] = tolower(str[i]);
  17680. }
  17681. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17683. isSuccess = ConfigurationStatus_Accepted;
  17684. }
  17685. else
  17686. {
  17687. isSuccess = ConfigurationStatus_Rejected;
  17688. }
  17689. }
  17690. if(strcmp(key, "FreeVendIdtag") == 0)
  17691. {
  17692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17693. {
  17694. strcpy(str, (const char*)value);
  17695. if(strlen(str) <= 20)
  17696. {
  17697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17698. isSuccess = ConfigurationStatus_Accepted;
  17699. }
  17700. else
  17701. {
  17702. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17703. isSuccess = ConfigurationStatus_Rejected;
  17704. }
  17705. }
  17706. else
  17707. {
  17708. isSuccess = ConfigurationStatus_Rejected;
  17709. }
  17710. }
  17711. if(strcmp(key, "OcppServer") == 0)
  17712. {
  17713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17714. {
  17715. strcpy(str, (const char*)value);
  17716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17717. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17718. isSuccess = ConfigurationStatus_Accepted;
  17719. }
  17720. else
  17721. {
  17722. isSuccess = ConfigurationStatus_Rejected;
  17723. }
  17724. }
  17725. if(strcmp(key, "MaintainServer") == 0)
  17726. {
  17727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17728. {
  17729. strcpy(str, (const char*)value);
  17730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17731. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17732. isSuccess = ConfigurationStatus_Accepted;
  17733. }
  17734. else
  17735. {
  17736. isSuccess = ConfigurationStatus_Rejected;
  17737. }
  17738. }
  17739. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17740. {
  17741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17742. {
  17743. strcpy(str, (const char*)value);
  17744. for(int i = 0; str[i]; i++)
  17745. {
  17746. str[i] = tolower(str[i]);
  17747. }
  17748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17749. isSuccess = ConfigurationStatus_Accepted;
  17750. }
  17751. else
  17752. {
  17753. isSuccess = ConfigurationStatus_Rejected;
  17754. }
  17755. }
  17756. if(strcmp(key, "StatusNotificationInterval") == 0)
  17757. {
  17758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17759. {
  17760. check_ascii = value[0];
  17761. if( (check_ascii < 48) || (check_ascii > 57) )
  17762. {
  17763. isSuccess = ConfigurationStatus_Rejected;
  17764. }
  17765. else
  17766. {
  17767. if((atoi(value) == 0) || (atoi(value) >= 10))
  17768. {
  17769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17770. isSuccess = ConfigurationStatus_Accepted;
  17771. }
  17772. else
  17773. isSuccess = ConfigurationStatus_Rejected;
  17774. }
  17775. }
  17776. else
  17777. {
  17778. isSuccess = ConfigurationStatus_Rejected;
  17779. }
  17780. }
  17781. if(strcmp(key, "PreAuthAmount") == 0)
  17782. {
  17783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17784. {
  17785. check_ascii = value[0];
  17786. if( (check_ascii < 48) || (check_ascii > 57) )
  17787. {
  17788. isSuccess = ConfigurationStatus_Rejected;
  17789. }
  17790. else
  17791. {
  17792. if(atof(value) >= 0)
  17793. {
  17794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17795. isSuccess = ConfigurationStatus_Accepted;
  17796. }
  17797. else
  17798. isSuccess = ConfigurationStatus_Rejected;
  17799. }
  17800. }
  17801. else
  17802. {
  17803. isSuccess = ConfigurationStatus_Rejected;
  17804. }
  17805. }
  17806. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17807. {
  17808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17809. {
  17810. check_ascii = value[0];
  17811. if( (check_ascii < 48) || (check_ascii > 57) )
  17812. {
  17813. isSuccess = ConfigurationStatus_Rejected;
  17814. }
  17815. else
  17816. {
  17817. if(atoi(value) >= 0)
  17818. {
  17819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17820. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17821. isSuccess = ConfigurationStatus_Accepted;
  17822. }
  17823. else
  17824. isSuccess = ConfigurationStatus_Rejected;
  17825. }
  17826. }
  17827. else
  17828. {
  17829. isSuccess = ConfigurationStatus_Rejected;
  17830. }
  17831. }
  17832. if(strcmp(key, "PowerSharingServerIP") == 0)
  17833. {
  17834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17835. {
  17836. strcpy(str, (const char*)value);
  17837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17838. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17839. isSuccess = ConfigurationStatus_Accepted;
  17840. }
  17841. else
  17842. {
  17843. isSuccess = ConfigurationStatus_Rejected;
  17844. }
  17845. }
  17846. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17847. {
  17848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17849. {
  17850. strcpy(str, (const char*)value);
  17851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17852. isSuccess = ConfigurationStatus_Accepted;
  17853. }
  17854. else
  17855. {
  17856. isSuccess = ConfigurationStatus_Rejected;
  17857. }
  17858. }
  17859. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17860. {
  17861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17862. {
  17863. if(atoi(value) > modelnameInfo.ratedPower)
  17864. {
  17865. isSuccess = ConfigurationStatus_Rejected;
  17866. }
  17867. else{
  17868. strcpy(str, (const char*)value);
  17869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17870. isSuccess = ConfigurationStatus_Accepted;
  17871. }
  17872. }
  17873. else
  17874. {
  17875. isSuccess = ConfigurationStatus_Rejected;
  17876. }
  17877. }
  17878. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  17879. {
  17880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17881. {
  17882. if((atoi(value) != 0) && (atoi(value) < 5))
  17883. {
  17884. isSuccess = ConfigurationStatus_Rejected;
  17885. }
  17886. else{
  17887. strcpy(str, (const char*)value);
  17888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  17889. isSuccess = ConfigurationStatus_Accepted;
  17890. }
  17891. }
  17892. else
  17893. {
  17894. isSuccess = ConfigurationStatus_Rejected;
  17895. }
  17896. }
  17897. #if 0
  17898. //For OCPP Test Case
  17899. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17900. {
  17901. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17902. {
  17903. strcpy(str, (const char*)value);
  17904. for(int i = 0; str[i]; i++)
  17905. {
  17906. str[i] = tolower(str[i]);
  17907. }
  17908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17909. isSuccess = ConfigurationStatus_Accepted;
  17910. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17911. }
  17912. else
  17913. {
  17914. isSuccess = ConfigurationStatus_Rejected;
  17915. }
  17916. }
  17917. #endif
  17918. #if 1
  17919. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17920. {
  17921. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17922. {
  17923. strcpy(str, (const char*)value);
  17924. for(int i = 0; str[i]; i++)
  17925. {
  17926. str[i] = tolower(str[i]);
  17927. }
  17928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17929. isSuccess = ConfigurationStatus_Accepted;
  17930. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17931. }
  17932. else
  17933. {
  17934. isSuccess = ConfigurationStatus_Rejected;
  17935. }
  17936. }
  17937. #endif
  17938. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17939. {
  17940. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17941. {
  17942. check_ascii = value[0];
  17943. if( (check_ascii < 48) || (check_ascii > 57) )
  17944. {
  17945. isSuccess = ConfigurationStatus_Rejected;
  17946. }
  17947. else
  17948. {
  17949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17950. isSuccess = ConfigurationStatus_Accepted;
  17951. }
  17952. }
  17953. else
  17954. {
  17955. isSuccess = ConfigurationStatus_Rejected;
  17956. }
  17957. }
  17958. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17959. {
  17960. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17961. {
  17962. check_ascii = value[0];
  17963. if( (check_ascii < 48) || (check_ascii > 57) )
  17964. {
  17965. isSuccess = ConfigurationStatus_Rejected;
  17966. }
  17967. else
  17968. {
  17969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17970. isSuccess = ConfigurationStatus_Accepted;
  17971. }
  17972. }
  17973. else
  17974. {
  17975. isSuccess = ConfigurationStatus_Rejected;
  17976. }
  17977. }
  17978. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17979. {
  17980. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17981. {
  17982. strcpy(str, (const char*)value);
  17983. for(int i = 0; str[i]; i++)
  17984. {
  17985. str[i] = tolower(str[i]);
  17986. }
  17987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17988. isSuccess = ConfigurationStatus_Accepted;
  17989. }
  17990. else
  17991. {
  17992. isSuccess = ConfigurationStatus_Rejected;
  17993. }
  17994. }
  17995. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17996. {
  17997. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17998. {
  17999. check_ascii = value[0];
  18000. if( (check_ascii < 48) || (check_ascii > 57) )
  18001. {
  18002. isSuccess = ConfigurationStatus_Rejected;
  18003. }
  18004. else
  18005. {
  18006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  18007. isSuccess = ConfigurationStatus_Accepted;
  18008. }
  18009. }
  18010. else
  18011. {
  18012. isSuccess = ConfigurationStatus_Rejected;
  18013. }
  18014. }
  18015. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  18016. {
  18017. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18018. {
  18019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  18020. isSuccess = ConfigurationStatus_Accepted;
  18021. }
  18022. else
  18023. {
  18024. isSuccess = ConfigurationStatus_Rejected;
  18025. }
  18026. }
  18027. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  18028. {
  18029. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18030. {
  18031. check_ascii = value[0];
  18032. if( (check_ascii < 48) || (check_ascii > 57) )
  18033. {
  18034. isSuccess = ConfigurationStatus_Rejected;
  18035. }
  18036. else
  18037. {
  18038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  18039. isSuccess = ConfigurationStatus_Accepted;
  18040. }
  18041. }
  18042. else
  18043. {
  18044. isSuccess = ConfigurationStatus_Rejected;
  18045. }
  18046. }
  18047. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  18048. {
  18049. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18050. {
  18051. strcpy(str, (const char*)value);
  18052. for(int i = 0; str[i]; i++)
  18053. {
  18054. str[i] = tolower(str[i]);
  18055. }
  18056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18057. isSuccess = ConfigurationStatus_Accepted;
  18058. }
  18059. else
  18060. {
  18061. isSuccess = ConfigurationStatus_Rejected;
  18062. }
  18063. }
  18064. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18065. {
  18066. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18067. {
  18068. check_ascii = value[0];
  18069. if( (check_ascii < 48) || (check_ascii > 57) )
  18070. {
  18071. isSuccess = ConfigurationStatus_Rejected;
  18072. }
  18073. else
  18074. {
  18075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18076. isSuccess = ConfigurationStatus_Accepted;
  18077. }
  18078. }
  18079. else
  18080. {
  18081. isSuccess = ConfigurationStatus_Rejected;
  18082. }
  18083. }
  18084. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18085. return isSuccess;
  18086. }
  18087. int TransactionMessageAttemptsGet(void)
  18088. {
  18089. return TransactionMessageAttemptsValue;
  18090. }
  18091. int FirstHeartBeatResponse(void)
  18092. {
  18093. return FirstHeartBeat;
  18094. }
  18095. int TransactionMessageRetryIntervalGet(void)
  18096. {
  18097. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18098. }
  18099. int ReadHttpStatus(int sock)
  18100. {
  18101. //char c;
  18102. char buff[1024]="",*ptr=buff+1;
  18103. int bytes_received, status;
  18104. DEBUG_INFO("Begin Response ..\n");
  18105. while((bytes_received = recv(sock, ptr, 1, 0))){
  18106. if(bytes_received==-1){
  18107. perror("ReadHttpStatus");
  18108. exit(1);
  18109. }
  18110. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18111. ptr++;
  18112. }
  18113. *ptr=0;
  18114. ptr=buff+1;
  18115. sscanf(ptr,"%*s %d ", &status);
  18116. DEBUG_INFO("%s\n",ptr);
  18117. DEBUG_INFO("status=%d\n",status);
  18118. DEBUG_INFO("End Response ..\n");
  18119. return (bytes_received>0)?status:0;
  18120. }
  18121. //the only filed that it parsed is 'Content-Length'
  18122. int ParseHeader(int sock)
  18123. {
  18124. //char c;
  18125. char buff[1024]="",*ptr=buff+4;
  18126. int bytes_received;
  18127. DEBUG_INFO("Begin HEADER ..\n");
  18128. while((bytes_received = recv(sock, ptr, 1, 0))){
  18129. if(bytes_received==-1){
  18130. perror("Parse Header");
  18131. exit(1);
  18132. }
  18133. if(
  18134. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18135. (ptr[-1]=='\r') && (*ptr=='\n' )
  18136. ) break;
  18137. ptr++;
  18138. }
  18139. *ptr=0;
  18140. ptr=buff+4;
  18141. //printf("%s",ptr);
  18142. if(bytes_received){
  18143. ptr=strstr(ptr,"Content-Length:");
  18144. if(ptr){
  18145. sscanf(ptr,"%*s %d",&bytes_received);
  18146. }else
  18147. bytes_received=-1; //unknown size
  18148. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18149. }
  18150. DEBUG_INFO("End HEADER ..\n");
  18151. return bytes_received ;
  18152. }
  18153. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18154. {
  18155. int result = TRUE;
  18156. char rmFileCmd[100]={0};
  18157. char FilePath[100]={0};
  18158. char ftpbuf[200];
  18159. int systemresult;
  18160. sprintf(FilePath,"/mnt/%s",filename);
  18161. system("ping 8.8.8.8 &");
  18162. if((access(FilePath,F_OK))!=-1)
  18163. {
  18164. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18165. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18166. system(rmFileCmd);
  18167. }
  18168. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18169. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18170. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18171. systemresult = system(ftpbuf);
  18172. if(systemresult != 0)
  18173. {
  18174. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18175. result = FALSE;
  18176. }
  18177. system("pkill ping");
  18178. return result;
  18179. }
  18180. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18181. {
  18182. int result = TRUE;
  18183. char rmFileCmd[100]={0};
  18184. char FilePath[100]={0};
  18185. char ftpbuf[200];
  18186. int systemresult;
  18187. sprintf(FilePath,"/mnt/%s",filename);
  18188. system("ping 8.8.8.8 &");
  18189. if((access(FilePath,F_OK))!=-1)
  18190. {
  18191. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18192. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18193. system(rmFileCmd);
  18194. }
  18195. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18196. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18197. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18198. systemresult = system(ftpbuf);
  18199. if(systemresult != 0)
  18200. {
  18201. DEBUG_WARN("scp error!\n");
  18202. result = FALSE;
  18203. }
  18204. system("pkill ping");
  18205. return result;
  18206. }
  18207. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18208. {
  18209. int result = TRUE;
  18210. char rmFileCmd[100]={0};
  18211. char FilePath[100]={0};
  18212. char ftpbuf[200];
  18213. int systemresult;
  18214. sprintf(FilePath,"/mnt/%s",filename);
  18215. system("ping 8.8.8.8 &");
  18216. if((access(FilePath,F_OK))!=-1)
  18217. {
  18218. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18219. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18220. system(rmFileCmd);
  18221. }
  18222. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18223. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18224. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18225. systemresult = system(ftpbuf);
  18226. if(systemresult != 0)
  18227. {
  18228. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18229. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18230. systemresult = system(ftpbuf);
  18231. if(systemresult != 0)
  18232. {
  18233. DEBUG_WARN("FTP download fail!\n");
  18234. result = FALSE;
  18235. }
  18236. }
  18237. system("pkill ping");
  18238. return result;
  18239. }
  18240. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18241. {
  18242. char rmFileCmd[100]={0};
  18243. char FilePath[100]={0};
  18244. char buf[512];
  18245. int systemresult = 0;
  18246. //DEBUG_INFO("filename=%s\n",filename);
  18247. //DEBUG_INFO("url=%s\n",url);
  18248. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18249. if((access(FilePath,F_OK))!=-1)
  18250. {
  18251. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18252. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18253. system(rmFileCmd);
  18254. }
  18255. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18256. if(fp == NULL)
  18257. {
  18258. DEBUG_INFO("log is NULL\n");
  18259. return FALSE;
  18260. }
  18261. else
  18262. {
  18263. fprintf(fp, "%s\n", url);
  18264. fprintf(fp, "%s\n", filename);
  18265. fclose(fp);
  18266. }
  18267. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18268. if(phpFP == NULL)
  18269. {
  18270. DEBUG_INFO("PHP upload fail.\n");
  18271. return FALSE;
  18272. }
  18273. else
  18274. {
  18275. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18276. {
  18277. if(strstr(buf, "result") != NULL)
  18278. {
  18279. sscanf(buf, "result: %d", &systemresult);
  18280. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18281. }
  18282. }
  18283. pclose(phpFP);
  18284. }
  18285. if(systemresult != 1)
  18286. {
  18287. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18288. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18289. if(phpFP == NULL)
  18290. {
  18291. DEBUG_WARN("PHP PUT upload fail.\n");
  18292. return FALSE;
  18293. }
  18294. else
  18295. {
  18296. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18297. {
  18298. if(strstr(buf, "result") != NULL)
  18299. {
  18300. sscanf(buf, "result: %d", &systemresult);
  18301. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18302. }
  18303. }
  18304. pclose(phpFP);
  18305. }
  18306. }
  18307. if(systemresult != 1)
  18308. {
  18309. DEBUG_WARN("PHP PUT upload fail.\n");
  18310. return FALSE;
  18311. }
  18312. return TRUE;
  18313. }
  18314. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18315. {
  18316. int result = FALSE;
  18317. char ftpbuf[200];
  18318. int systemresult;
  18319. /*
  18320. // Domaind name transfer to IP address
  18321. struct hostent* server;
  18322. char *IPbuffer;
  18323. server = gethostbyname(location);
  18324. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18325. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18326. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18327. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18328. systemresult = system(ftpbuf);
  18329. if(systemresult != 0)
  18330. {
  18331. DEBUG_INFO("ftpput error!\n");
  18332. }
  18333. else
  18334. {
  18335. result = TRUE;
  18336. DEBUG_INFO("ftpput OK!\n");
  18337. }
  18338. return result;
  18339. }
  18340. int GetOcppServerURL()
  18341. {
  18342. int result = FALSE;
  18343. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18344. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18345. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18346. struct yuarel url;
  18347. char urlStr[512];
  18348. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18349. {
  18350. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18351. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18352. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18353. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18354. if(yuarel_parse(&url, urlStr) != -1)
  18355. {
  18356. sprintf(OcppProtocol, "%s", url.scheme);
  18357. sprintf(OcppHost, "%s", url.host);
  18358. if(url.path == NULL)
  18359. OcppTempPath[0] = '\0';
  18360. else
  18361. {
  18362. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18363. {
  18364. sprintf(OcppTempPath, "%s/", url.path);
  18365. }
  18366. else
  18367. {
  18368. sprintf(OcppTempPath, "%s", url.path);
  18369. }
  18370. }
  18371. if(url.port == 0)
  18372. {
  18373. if(strcmp(OcppProtocol, "wss") == 0)
  18374. OcppPort = 443;
  18375. else
  18376. OcppPort = 80;
  18377. }
  18378. else
  18379. OcppPort = url.port;
  18380. result = TRUE;
  18381. }
  18382. }
  18383. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18384. {
  18385. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18386. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18387. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18388. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18389. if(yuarel_parse(&url, urlStr) != -1)
  18390. {
  18391. sprintf(OcppProtocol, "%s", url.scheme);
  18392. sprintf(OcppHost, "%s", url.host);
  18393. if(url.path == NULL)
  18394. OcppTempPath[0] = '\0';
  18395. else
  18396. sprintf(OcppTempPath, "%s", url.path);
  18397. if(url.port == 0)
  18398. {
  18399. if(strcmp(OcppProtocol, "wss") == 0)
  18400. OcppPort = 443;
  18401. else
  18402. OcppPort = 80;
  18403. }
  18404. else
  18405. OcppPort = url.port;
  18406. result = TRUE;
  18407. }
  18408. }
  18409. else
  18410. {
  18411. strcpy(OcppHost,"");
  18412. }
  18413. return result;
  18414. }
  18415. int GetOcppPath()
  18416. {
  18417. int result = FALSE;
  18418. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18419. {
  18420. if(OcppTempPath == NULL)
  18421. {
  18422. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18423. }
  18424. else
  18425. {
  18426. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18427. }
  18428. result = TRUE;
  18429. goto End;
  18430. }
  18431. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18432. {
  18433. if(OcppTempPath == NULL)
  18434. {
  18435. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18436. }
  18437. else
  18438. {
  18439. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18440. }
  18441. result = TRUE;
  18442. goto End;
  18443. }
  18444. else
  18445. {
  18446. strcpy(OcppPath,"");
  18447. }
  18448. End:
  18449. return result;
  18450. }
  18451. int GetOcppPort()
  18452. {
  18453. return OcppPort;
  18454. }
  18455. int GetOcppConnStatus(void)
  18456. {
  18457. return ShmOCPP16Data->OcppConnStatus;
  18458. }
  18459. void SetOcppConnStatus(uint8_t status)
  18460. {
  18461. ShmOCPP16Data->OcppConnStatus = status;
  18462. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18463. }
  18464. int GetHeartBeatWithNOResponse(void)
  18465. {
  18466. return HeartBeatWithNOResponse;
  18467. }
  18468. void SetHeartBeatWithNOResponse(void)
  18469. {
  18470. HeartBeatWithNOResponse = 0;
  18471. }
  18472. void GetStartTransactionIdTag(int gun_index)
  18473. {
  18474. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18475. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18476. }
  18477. int GetStartTransactionId(int gun_index)
  18478. {
  18479. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18480. }
  18481. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18482. {
  18483. char ch;
  18484. FILE *fptr1;
  18485. int temptransactionId;
  18486. char str[100]={0};
  18487. temptransactionId = 0;
  18488. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18489. {
  18490. DEBUG_INFO("IdTag is empty.\n");
  18491. return temptransactionId;
  18492. }
  18493. /*------ Read the file ----------------*/
  18494. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18495. if (!fptr1)
  18496. {
  18497. DEBUG_INFO("QueueTransactionId file open error.\n");
  18498. //printf(" File not found or unable to open the input file!!\n");
  18499. return temptransactionId;
  18500. }
  18501. ch=fgetc(fptr1);
  18502. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18503. rewind(fptr1);
  18504. if(ch!=EOF)
  18505. {
  18506. // printf("%c",ch);
  18507. while (fgets(str, 100, fptr1) != NULL)
  18508. {
  18509. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18510. if(str[0]=='\0')
  18511. {
  18512. break;
  18513. }
  18514. char *revbuf[8] = {0}; // Variable store string split
  18515. int num = 0;// Quantity after string split
  18516. DEBUG_INFO("Transaction queue data= %s\n", str);
  18517. splitstring(str,",",revbuf,&num); // String split
  18518. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18519. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18520. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18521. DEBUG_INFO("------------------------------\n");
  18522. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18523. {
  18524. if(isStopTransaction)
  18525. {
  18526. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18527. {
  18528. temptransactionId = atoi(revbuf[2]);
  18529. //break;
  18530. }
  18531. }
  18532. else
  18533. {
  18534. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18535. {
  18536. temptransactionId = atoi(revbuf[2]);
  18537. //break;
  18538. }
  18539. }
  18540. }
  18541. }
  18542. }
  18543. else
  18544. DEBUG_INFO("EOF\n");
  18545. fclose(fptr1);
  18546. /*------- End of reading ---------------*/
  18547. return temptransactionId;
  18548. }
  18549. void SetTransactionIdZero(int transactionId)
  18550. {
  18551. char ch;
  18552. FILE *fptr1, *fptr2;
  18553. int temptransactionId = 0;
  18554. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18555. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18556. if (!fptr1)
  18557. {
  18558. //printf(" File not found or unable to open the input file!!\n");
  18559. return ;
  18560. }
  18561. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18562. if (!fptr2)
  18563. {
  18564. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18565. fclose(fptr1);
  18566. return ;
  18567. }
  18568. ch=fgetc(fptr1);
  18569. rewind(fptr1);
  18570. if(ch!=EOF)
  18571. {
  18572. // copy all contents to the temporary file except the specific line
  18573. while (fgets(str, 100, fptr1) != NULL)
  18574. {
  18575. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18576. if(str[0]=='\0')
  18577. {
  18578. break;
  18579. }
  18580. char *revbuf[8] = {0};
  18581. int num = 0;
  18582. strcpy(strtemp, str);
  18583. splitstring(str,",",revbuf,&num);
  18584. if(revbuf[2][0] != '\0')
  18585. {
  18586. temptransactionId = atoi(revbuf[2]);
  18587. if(transactionId != temptransactionId)
  18588. {
  18589. fprintf(fptr2, "%s\n", strtemp);
  18590. }
  18591. }
  18592. }
  18593. }
  18594. fclose(fptr1);
  18595. fclose(fptr2);
  18596. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18597. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18598. /*------ Read the file ----------------*/
  18599. }
  18600. int InternetDisconnect(void)
  18601. {
  18602. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18603. }
  18604. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18605. void storeTempStopTransaction(int gun_index)
  18606. {
  18607. char guid[37]={0};
  18608. int tempIndex = 0;
  18609. char TempStopTransaction[256];
  18610. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18611. DEBUG_INFO("storeTempStopTransaction...\n");
  18612. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18613. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18614. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18615. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18616. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18617. {
  18618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18619. {
  18620. tempIndex = ((gun_index==2) ? 1: 0);
  18621. }
  18622. else
  18623. {
  18624. tempIndex = gun_index;
  18625. }
  18626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18627. {
  18628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18629. {
  18630. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18631. }
  18632. }// END OF CHAdeMO_QUANTITY
  18633. }
  18634. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18635. {
  18636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18637. {
  18638. tempIndex = ((gun_index==2) ? 1: 0);
  18639. }
  18640. else
  18641. {
  18642. tempIndex = gun_index;
  18643. }
  18644. for (int index = 0; index < CCS_QUANTITY; index++)
  18645. {
  18646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18647. {
  18648. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18649. }
  18650. }// END OF CCS_QUANTITY
  18651. }
  18652. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18653. {
  18654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18655. {
  18656. tempIndex = ((gun_index==2) ? 1: 0);
  18657. }
  18658. else
  18659. {
  18660. tempIndex = gun_index;
  18661. }
  18662. for (int index = 0; index < GB_QUANTITY; index++)
  18663. {
  18664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18665. {
  18666. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18667. }
  18668. }// END OF GB_QUANTITY
  18669. }
  18670. else if(gunType[gun_index] == GUN_TYPE_DO)
  18671. {
  18672. tempIndex = gun_index;
  18673. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18674. {
  18675. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18676. {
  18677. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18678. }
  18679. }
  18680. }
  18681. else
  18682. {
  18683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18684. {
  18685. tempIndex = 2;
  18686. }
  18687. else
  18688. {
  18689. tempIndex = gun_index;
  18690. }
  18691. for (int index = 0; index < AC_QUANTITY; index++)
  18692. {
  18693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18694. {
  18695. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18696. }
  18697. }// END OF AC_QUANTITY
  18698. }
  18699. //Stop Transaction Time
  18700. struct timeval tmnow;
  18701. struct tm *tm;
  18702. char buf[28];//, usec_buf[6];
  18703. gettimeofday(&tmnow, NULL);
  18704. time_t t;
  18705. t = time(NULL);
  18706. /*UTC time and date*/
  18707. tm = gmtime(&t);
  18708. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18710. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18712. random_uuid(guid);
  18713. /***********************************transactionData******************************************************/
  18714. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18716. //=================================
  18717. //1. Transaction_Begin
  18718. //=================================
  18719. //============================== Energy.Active.Import.Interval ===========================================
  18720. //=================================
  18721. //2. Transaction_End
  18722. //=================================
  18723. //2.1====================================== Current.Import L1 ==============================================
  18724. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18725. {
  18726. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18728. {
  18729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18730. {
  18731. tempIndex = ((gun_index==2) ? 1: 0);
  18732. }
  18733. else
  18734. {
  18735. tempIndex = gun_index;
  18736. }
  18737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18738. {
  18739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18740. {
  18741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18742. }
  18743. }// End of for CHAdeMO_QUANTITY
  18744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18745. }
  18746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18747. {
  18748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18749. {
  18750. tempIndex = ((gun_index==2) ? 1: 0);
  18751. }
  18752. else
  18753. {
  18754. tempIndex = gun_index;
  18755. }
  18756. for (int index = 0; index < CCS_QUANTITY; index++)
  18757. {
  18758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18759. {
  18760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18761. }
  18762. }// End of for CCS_QUANTITY
  18763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18764. }
  18765. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18766. {
  18767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18768. {
  18769. tempIndex = ((gun_index==2) ? 1: 0);
  18770. }
  18771. else
  18772. {
  18773. tempIndex = gun_index;
  18774. }
  18775. for (int index = 0; index < GB_QUANTITY; index++)
  18776. {
  18777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18778. {
  18779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18780. }
  18781. }// End of for GB_QUANTITY
  18782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18783. }
  18784. else if(gunType[gun_index] == GUN_TYPE_DO)
  18785. {
  18786. tempIndex = gun_index;
  18787. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18788. {
  18789. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18790. {
  18791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18792. }
  18793. }
  18794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18795. }
  18796. else
  18797. {
  18798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18799. {
  18800. tempIndex = 2;
  18801. }
  18802. else
  18803. {
  18804. tempIndex = gun_index;
  18805. }
  18806. for (int index = 0; index < AC_QUANTITY; index++)
  18807. {
  18808. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18809. {
  18810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18811. }
  18812. }// End of for AC_QUANTITY
  18813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18814. }
  18815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18818. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18821. }
  18822. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18823. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18824. {
  18825. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18826. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18827. {
  18828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18829. {
  18830. tempIndex = ((gun_index==2) ? 1: 0);
  18831. }
  18832. else
  18833. {
  18834. tempIndex = gun_index;
  18835. }
  18836. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18837. {
  18838. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18839. {
  18840. 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
  18841. }
  18842. }// END OF CHAdeMO_QUANTITY
  18843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18844. }
  18845. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18846. {
  18847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18848. {
  18849. tempIndex = ((gun_index==2) ? 1: 0);
  18850. }
  18851. else
  18852. {
  18853. tempIndex = gun_index;
  18854. }
  18855. for (int index = 0; index < CCS_QUANTITY; index++)
  18856. {
  18857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18858. {
  18859. 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
  18860. }
  18861. }// END OF CCS_QUANTITY
  18862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18863. }
  18864. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18865. {
  18866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18867. {
  18868. tempIndex = ((gun_index==2) ? 1: 0);
  18869. }
  18870. else
  18871. {
  18872. tempIndex = gun_index;
  18873. }
  18874. for (int index = 0; index < GB_QUANTITY; index++)
  18875. {
  18876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18877. {
  18878. 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
  18879. }
  18880. }// END OF GB_QUANTITY
  18881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18882. }
  18883. else if(gunType[gun_index] == GUN_TYPE_DO)
  18884. {
  18885. tempIndex = gun_index;
  18886. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18887. {
  18888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18889. {
  18890. 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
  18891. }
  18892. }
  18893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18894. }
  18895. else
  18896. {
  18897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18898. {
  18899. tempIndex = 2;
  18900. }
  18901. else
  18902. {
  18903. tempIndex = gun_index;
  18904. }
  18905. for (int index = 0; index < AC_QUANTITY; index++)
  18906. {
  18907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18908. {
  18909. 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
  18910. }
  18911. }// END OF AC_QUANTITY
  18912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18913. }
  18914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18917. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18920. }
  18921. //2.3====================================== Power.Active.Import =========================================
  18922. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18923. {
  18924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18926. {
  18927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18928. {
  18929. tempIndex = ((gun_index==2) ? 1: 0);
  18930. }
  18931. else
  18932. {
  18933. tempIndex = gun_index;
  18934. }
  18935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18936. {
  18937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18938. {
  18939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18940. }
  18941. } // End for CHAdeMO_QUANTITY
  18942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18943. }
  18944. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18945. {
  18946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18947. {
  18948. tempIndex = ((gun_index==2) ? 1: 0);
  18949. }
  18950. else
  18951. {
  18952. tempIndex = gun_index;
  18953. }
  18954. for (int index = 0; index < CCS_QUANTITY; index++)
  18955. {
  18956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18957. {
  18958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18959. }
  18960. } // END for CCS_QUANTITY
  18961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18962. }
  18963. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18964. {
  18965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18966. {
  18967. tempIndex = ((gun_index==2) ? 1: 0);
  18968. }
  18969. else
  18970. {
  18971. tempIndex = gun_index;
  18972. }
  18973. for (int index = 0; index < GB_QUANTITY; index++)
  18974. {
  18975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18976. {
  18977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18978. }
  18979. }// END for GB_QUANTITY
  18980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18981. }
  18982. else if(gunType[gun_index] == GUN_TYPE_DO)
  18983. {
  18984. tempIndex = gun_index;
  18985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18986. {
  18987. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18988. {
  18989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18990. }
  18991. }
  18992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18993. }
  18994. else
  18995. {
  18996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18997. {
  18998. tempIndex = 2;
  18999. }
  19000. else
  19001. {
  19002. tempIndex = gun_index;
  19003. }
  19004. for (int index = 0; index < AC_QUANTITY; index++)
  19005. {
  19006. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19007. {
  19008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19009. }
  19010. } // END for AC_QUANTITY
  19011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19012. }
  19013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  19015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  19016. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  19018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  19019. }
  19020. //2.4====================================== Voltage L1 ====================================================
  19021. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19022. {
  19023. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19025. {
  19026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19027. {
  19028. tempIndex = ((gun_index==2) ? 1: 0);
  19029. }
  19030. else
  19031. {
  19032. tempIndex = gun_index;
  19033. }
  19034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19035. {
  19036. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19037. {
  19038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19039. }
  19040. } // END OF FOR CHAdeMO_QUANTITY
  19041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19042. }
  19043. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19044. {
  19045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19046. {
  19047. tempIndex = ((gun_index==2) ? 1: 0);
  19048. }
  19049. else
  19050. {
  19051. tempIndex = gun_index;
  19052. }
  19053. for (int index = 0; index < CCS_QUANTITY; index++)
  19054. {
  19055. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19056. {
  19057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19058. }
  19059. } // END OF FOR CCS_QUANTITY
  19060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19061. }
  19062. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19063. {
  19064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19065. {
  19066. tempIndex = ((gun_index==2) ? 1: 0);
  19067. }
  19068. else
  19069. {
  19070. tempIndex = gun_index;
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19077. }
  19078. } // END OF FOR GB_QUANTITY
  19079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19080. }
  19081. else if(gunType[gun_index] == GUN_TYPE_DO)
  19082. {
  19083. tempIndex = gun_index;
  19084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19085. {
  19086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19087. {
  19088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19089. }
  19090. }
  19091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19092. }
  19093. else
  19094. {
  19095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19096. {
  19097. tempIndex = 2;
  19098. }
  19099. else
  19100. {
  19101. tempIndex = gun_index;
  19102. }
  19103. for (int index = 0; index < AC_QUANTITY; index++)
  19104. {
  19105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19106. {
  19107. 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
  19108. }
  19109. } // END OF FOR AC_QUANTITY
  19110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19111. }
  19112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19115. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19118. }
  19119. //2.5============================================== End SoC =========================================================
  19120. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19121. {
  19122. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19123. 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))
  19124. {
  19125. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19126. {
  19127. tempIndex = ((gun_index==2) ? 1: 0);
  19128. }
  19129. else
  19130. {
  19131. tempIndex = gun_index;
  19132. }
  19133. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19134. {
  19135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19136. {
  19137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19138. {
  19139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19140. }
  19141. }
  19142. }
  19143. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19144. {
  19145. for (int index = 0; index < CCS_QUANTITY; index++)
  19146. {
  19147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19148. {
  19149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19150. }
  19151. }
  19152. }
  19153. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19154. {
  19155. for (int index = 0; index < GB_QUANTITY; index++)
  19156. {
  19157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19158. {
  19159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19160. }
  19161. }
  19162. }
  19163. else if(gunType[gun_index] == GUN_TYPE_DO)
  19164. {
  19165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19166. {
  19167. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19168. {
  19169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19170. }
  19171. }
  19172. }
  19173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19179. } // END FOR DC CASE
  19180. }
  19181. //2.6====================================== Current.Import L2 ==============================================
  19182. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19183. {
  19184. // AC 3 phase L2 current
  19185. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19186. {
  19187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19188. {
  19189. tempIndex = 2;
  19190. }
  19191. else
  19192. {
  19193. tempIndex = gun_index;
  19194. }
  19195. for (int index = 0; index < AC_QUANTITY; index++)
  19196. {
  19197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19198. {
  19199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19200. }
  19201. }// End of for AC_QUANTITY
  19202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19203. }
  19204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19209. }
  19210. //2.7====================================== Current.Import L3 ==============================================
  19211. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19212. {
  19213. // AC 3 phase L3 current
  19214. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19215. {
  19216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19217. {
  19218. tempIndex = 2;
  19219. }
  19220. else
  19221. {
  19222. tempIndex = gun_index;
  19223. }
  19224. for (int index = 0; index < AC_QUANTITY; index++)
  19225. {
  19226. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19227. {
  19228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19229. }
  19230. }// End of for AC_QUANTITY
  19231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19232. }
  19233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19238. }
  19239. //2.9====================================== Voltage L2 ====================================================
  19240. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19241. {
  19242. // AC 3 phase L2 volatge
  19243. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19244. {
  19245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19246. {
  19247. tempIndex = 2;
  19248. }
  19249. else
  19250. {
  19251. tempIndex = gun_index;
  19252. }
  19253. for (int index = 0; index < AC_QUANTITY; index++)
  19254. {
  19255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19256. {
  19257. 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
  19258. }
  19259. } // END OF FOR AC_QUANTITY
  19260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19261. }
  19262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19267. }
  19268. //2.10====================================== Voltage L3 ====================================================
  19269. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19270. {
  19271. // AC 3 phase L3 volatge
  19272. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19273. {
  19274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19275. {
  19276. tempIndex = 2;
  19277. }
  19278. else
  19279. {
  19280. tempIndex = gun_index;
  19281. }
  19282. for (int index = 0; index < AC_QUANTITY; index++)
  19283. {
  19284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19285. {
  19286. 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
  19287. }
  19288. } // END OF FOR AC_QUANTITY
  19289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19290. }
  19291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19296. }
  19297. //====================== Start SoC ================================
  19298. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19299. {
  19300. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19301. 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))
  19302. {
  19303. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19304. {
  19305. tempIndex = ((gun_index==2) ? 1: 0);
  19306. }
  19307. else
  19308. {
  19309. tempIndex = gun_index;
  19310. }
  19311. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19312. {
  19313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19314. {
  19315. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19316. {
  19317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19318. }
  19319. }
  19320. }
  19321. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19322. {
  19323. for (int index = 0; index < CCS_QUANTITY; index++)
  19324. {
  19325. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19326. {
  19327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19328. }
  19329. }
  19330. }
  19331. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19332. {
  19333. for (int index = 0; index < GB_QUANTITY; index++)
  19334. {
  19335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19336. {
  19337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19338. }
  19339. }
  19340. }
  19341. else if(gunType[gun_index] == GUN_TYPE_DO)
  19342. {
  19343. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19344. {
  19345. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19346. {
  19347. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19348. }
  19349. }
  19350. }
  19351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19357. } // END FOR DC CASE
  19358. }
  19359. //======================================== Message create ==============================================
  19360. json_object *StopTransaction = json_object_new_object();
  19361. json_object *transactionDatas = json_object_new_array();
  19362. json_object *sampledValues = json_object_new_array();
  19363. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19364. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19365. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19366. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19367. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19368. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19369. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19370. {
  19371. json_object *transactionData = json_object_new_object();
  19372. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19373. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19374. {
  19375. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19376. {
  19377. json_object *sampledValue = json_object_new_object();
  19378. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19379. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19380. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19381. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19382. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19383. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19384. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19385. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19386. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19387. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19388. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19389. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19390. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19391. json_object_array_add(sampledValues, sampledValue);
  19392. }
  19393. }
  19394. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19395. json_object_array_add(transactionDatas, transactionData);
  19396. }
  19397. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19398. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19399. ,MESSAGE_TYPE_CALL
  19400. ,guid
  19401. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19402. json_object_put(StopTransaction);
  19403. // Check File "TempStopTransaction" Exist
  19404. if((access(TempStopTransaction,F_OK))!=-1)
  19405. {
  19406. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19407. fclose(fopen(TempStopTransaction, "w"));
  19408. }
  19409. else
  19410. {
  19411. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19412. FILE *log = fopen(TempStopTransaction, "w+");
  19413. if(log == NULL)
  19414. {
  19415. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19416. return ;
  19417. }
  19418. else
  19419. {
  19420. fclose(log);
  19421. }
  19422. }
  19423. //Add TempStopTransaction | Update TempStopTransaction
  19424. // open file for writing
  19425. FILE *outfile;
  19426. outfile = fopen (TempStopTransaction, "a");
  19427. //DEBUG_INFO("data = %s\n", queuedata);
  19428. fputs(queuedata, outfile);
  19429. fputs("\n", outfile);
  19430. fclose (outfile);
  19431. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19432. OCPP_updatePeriodEnergy(gun_index);
  19433. }
  19434. void checkTempStopTransaction(int gun_index)
  19435. {
  19436. FILE *fptr1;
  19437. char ch;
  19438. char str[QUEUE_MESSAGE_LENGTH]={0};
  19439. char guid[37]={0};
  19440. char tempdata[65]={0};
  19441. char connectorStr[2]={0};
  19442. char TempStopTransaction[256];
  19443. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19444. fptr1 = fopen(TempStopTransaction, "r");
  19445. //TempStopTransaction格式: 槍號,StopTransaction封包
  19446. if (!fptr1)
  19447. {
  19448. //printf(" File not found or unable to open the input file!!\n");
  19449. return ;
  19450. }
  19451. ch=fgetc(fptr1);
  19452. //printf(" Now the content of the file %s is : \n",fname);
  19453. rewind(fptr1);
  19454. if(ch!=EOF)
  19455. {
  19456. // copy all contents to the temporary file except the specific line
  19457. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19458. {
  19459. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19460. if(str[0]=='\0')
  19461. {
  19462. break;
  19463. }
  19464. //TempStopTransaction格式: 槍號,StopTransaction封包
  19465. strncpy(connectorStr, str, 1);
  19466. if(atoi(connectorStr) != (gun_index+1))
  19467. {
  19468. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19469. fclose(fptr1);
  19470. return ;
  19471. }
  19472. //random_uuid(guid);
  19473. strncpy(guid, str+6, 36); //copy guid
  19474. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19475. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19476. {
  19477. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19478. }
  19479. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19480. OCPP_insert_transaction_msg(NO, str);
  19481. memset(str,0,ARRAY_SIZE(str));
  19482. }
  19483. }
  19484. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19485. fclose(fptr1);
  19486. remove(TempStopTransaction); // remove the original file
  19487. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19488. }
  19489. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19490. {
  19491. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19492. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19493. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19494. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19495. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19496. }
  19497. int GetWebSocketPingInterval(void)
  19498. {
  19499. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19500. }
  19501. int GetServerSign(void)
  19502. {
  19503. return server_sign;
  19504. }
  19505. uint8_t GetOcppSecurityProfile()
  19506. {
  19507. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19508. }
  19509. void GetOcppChargerBoxId(uint8_t *data)
  19510. {
  19511. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19512. }
  19513. void GetOcppSecurityPassword(uint8_t *data)
  19514. {
  19515. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19516. }
  19517. void SetOcppVersion(uint8_t *version)
  19518. {
  19519. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19520. DEBUG_INFO("ocpp version: %s\n", version);
  19521. if(strstr((char*)version, "ocpp1.6") != NULL)
  19522. {
  19523. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19524. }
  19525. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19526. {
  19527. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19528. system("pkill OcppBackend");
  19529. }
  19530. }
  19531. void SetServerSign(int value)
  19532. {
  19533. server_sign = value;
  19534. }
  19535. int GetBootNotificationInterval(void)
  19536. {
  19537. return BootNotificationInterval;
  19538. }
  19539. int GetInternetConn(void)
  19540. {
  19541. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19542. }
  19543. int GetBackendConnectionTimeout(void)
  19544. {
  19545. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19546. }
  19547. int isConnectorInitMode(int gun_index)
  19548. {
  19549. int tempIndex = 0;
  19550. int result = TRUE;
  19551. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19552. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19553. {
  19554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19555. {
  19556. tempIndex = ((gun_index==2) ? 1: 0);
  19557. }
  19558. else
  19559. {
  19560. tempIndex = gun_index;
  19561. }
  19562. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19563. {
  19564. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19565. {
  19566. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19567. } //end of the same index
  19568. }//end of for CHAdeMO_QUANTITY
  19569. }
  19570. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19571. {
  19572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19573. {
  19574. tempIndex = ((gun_index==2) ? 1: 0);
  19575. }
  19576. else
  19577. {
  19578. tempIndex = gun_index;
  19579. }
  19580. for (int index = 0; index < CCS_QUANTITY; index++)
  19581. {
  19582. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19583. {
  19584. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19585. } //end of the same index
  19586. } // end of for CCS_QUANTITY
  19587. }
  19588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19589. {
  19590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19591. {
  19592. tempIndex = ((gun_index==2) ? 1: 0);
  19593. }
  19594. else
  19595. {
  19596. tempIndex = gun_index;
  19597. }
  19598. for (int index = 0; index < GB_QUANTITY; index++)
  19599. {
  19600. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19601. {
  19602. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19603. } //end of the same index
  19604. } // end of for GB_QUANTITY
  19605. }
  19606. else if(gunType[gun_index] == GUN_TYPE_DO)
  19607. {
  19608. tempIndex = gun_index;
  19609. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19610. {
  19611. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19612. {
  19613. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19614. } //end of the same index
  19615. }
  19616. }
  19617. else
  19618. {
  19619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19620. {
  19621. tempIndex = 2;
  19622. }
  19623. else
  19624. {
  19625. tempIndex = gun_index;
  19626. }
  19627. for (int index = 0; index < AC_QUANTITY; index++)
  19628. {
  19629. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19630. {
  19631. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19632. }//end of the same index
  19633. }//end of for AC_QUANTITY
  19634. }
  19635. return result;
  19636. }
  19637. void refreshProcDogTimer()
  19638. {
  19639. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19640. }
  19641. void InitialSystemValue(void)
  19642. {
  19643. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19644. locallistVersion=0;
  19645. BootNotificationInterval = 0;
  19646. authorizeRetryTimes = 0;
  19647. GunStatusInterval = 10;
  19648. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19649. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19650. //Hear Beat
  19651. HeartBeatWithNOResponse = 0;
  19652. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19653. FirstHeartBeat = 0;
  19654. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19655. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19656. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19657. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19658. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19659. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19660. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19661. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19662. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19663. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19664. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19665. //Status && ConnectorPlugIn Setting
  19666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19667. {
  19668. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19669. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19670. }
  19671. for (int index = 0; index < CCS_QUANTITY; index++)
  19672. {
  19673. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19674. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19675. }
  19676. for (int index = 0; index < GB_QUANTITY; index++)
  19677. {
  19678. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19679. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19680. }
  19681. for (int index = 0; index < AC_QUANTITY; index++)
  19682. {
  19683. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19684. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19685. }
  19686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19687. {
  19688. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19689. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19690. }
  19691. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19692. {
  19693. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19694. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19695. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19696. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19697. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19698. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19699. }
  19700. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19701. refreshStartTimer(&clientTime.Heartbeat);
  19702. sleep(1);
  19703. }
  19704. void LWS_Send(char *str)
  19705. {
  19706. //=====================================================
  19707. // Check InternetConn 0: disconnected, 1: connected
  19708. //====================================================
  19709. if(GetOcppConnStatus() == 0)
  19710. {
  19711. DEBUG_INFO("offline now !!!\n");
  19712. return;
  19713. }
  19714. // Only disable isWebsocketSendable operation initiated by charger
  19715. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19716. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19717. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19718. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19719. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19720. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19721. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19722. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19723. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19724. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19725. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19726. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19727. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19728. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19729. {
  19730. isWebsocketSendable = 0;
  19731. }
  19732. pthread_mutex_lock(&lock_send);
  19733. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19734. sprintf((char *)SendBuffer, "%s", str);
  19735. SendBufLen = strlen(str);
  19736. pthread_mutex_unlock(&lock_send);
  19737. lws_callback_on_writable(wsi_client);
  19738. //lws_service(context, 0);
  19739. //sleep(1);
  19740. }
  19741. void LWS_SendNow(char *str)
  19742. {
  19743. //=====================================================
  19744. // Check InternetConn 0: disconnected, 1: connected
  19745. //====================================================
  19746. if(GetOcppConnStatus() == 0)
  19747. {
  19748. DEBUG_INFO("offline now !!!\n");
  19749. return;
  19750. }
  19751. // Only disable isWebsocketSendable operation initiated by charger
  19752. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19753. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19754. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19755. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19756. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19757. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19758. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19759. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19760. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19761. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19762. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19763. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19764. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19765. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19766. {
  19767. isWebsocketSendable = 0;
  19768. }
  19769. pthread_mutex_lock(&lock_send);
  19770. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19771. sprintf((char *)SendBuffer, "%s", str);
  19772. SendBufLen = strlen(str);
  19773. pthread_mutex_unlock(&lock_send);
  19774. lws_callback_on_writable(wsi_client);
  19775. lws_service(context, 0);
  19776. //sleep(1);
  19777. }