MessageHandler.c 983 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520
  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. }clientTime;
  117. typedef union
  118. {
  119. //Operations Initiated by Central System
  120. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  121. struct
  122. {
  123. //CsMsgValue[0]
  124. unsigned char StatusNotificationReq:1; //bit 0,
  125. unsigned char StatusNotificationConf:1; //bit 1,
  126. unsigned char TriggerMeterValue:1; //bit 2,
  127. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  128. unsigned char isOnCharging:1; //bit 4,
  129. unsigned char :3; //bit5~7
  130. }bits[CONNECTOR_QUANTITY];
  131. }CpinitiateMsg;
  132. CpinitiateMsg cpinitateMsg;
  133. //GetConfiguration Array
  134. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  135. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  137. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  138. static char *ChargePointErrorCodeStr[] = {
  139. MACROSTR(ConnectorLockFailure),
  140. MACROSTR(EVCommunicationError),
  141. MACROSTR(GroundFailure),
  142. MACROSTR(HighTemperature),
  143. MACROSTR(InternalError),
  144. MACROSTR(LocalListConflict),
  145. MACROSTR(NoError),
  146. MACROSTR(OtherError),
  147. MACROSTR(OverCurrentFailure),
  148. MACROSTR(OverVoltage),
  149. MACROSTR(PowerMeterFailure),
  150. MACROSTR(PowerSwitchFailure),
  151. MACROSTR(ReaderFailure),
  152. MACROSTR(ResetFailure),
  153. MACROSTR(UnderVoltage),
  154. MACROSTR(WeakSignal)
  155. };
  156. static char * ChargePointStatusStr[] = {
  157. MACROSTR(Available),
  158. MACROSTR(Preparing),
  159. MACROSTR(Charging),
  160. MACROSTR(SuspendedEVSE),
  161. MACROSTR(SuspendedEV),
  162. MACROSTR(Finishing),
  163. MACROSTR(Reserved),
  164. MACROSTR(Unavailable),
  165. MACROSTR(Faulted)
  166. };
  167. static char *RegistrationStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Pending),
  170. MACROSTR(Rejected)
  171. };
  172. static char *AvailabilityTypeStr[] = {
  173. MACROSTR(Inoperative),
  174. MACROSTR(Operative)
  175. };
  176. static char *AvailabilityStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected),
  179. MACROSTR(Scheduled)
  180. };
  181. static char *ConfigurationStatusStr[] = {
  182. MACROSTR(Accepted),
  183. MACROSTR(Rejected),
  184. MACROSTR(RebootRequired),
  185. MACROSTR(NotSupported)
  186. };
  187. static char *ClearCacheStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected)
  190. };
  191. static char *ChargingProfilePurposeTypeStr[] = {
  192. MACROSTR(ChargePointMaxProfile),
  193. MACROSTR(TxDefaultProfile),
  194. MACROSTR(TxProfile)
  195. };
  196. static char *ChargingProfileStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected),
  199. MACROSTR(NotSupported)
  200. };
  201. static char *ClearChargingProfileStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Unknown)
  204. };
  205. static char *GetCompositeScheduleStatusStr[] = {
  206. MACROSTR(Accepted),
  207. MACROSTR(Rejected)
  208. };
  209. static char *UpdateTypeStr[] = {
  210. MACROSTR(Differential),
  211. MACROSTR(Full)
  212. };
  213. static char *UpdateStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Failed),
  216. MACROSTR(NotSupported),
  217. MACROSTR(VersionMismatch)
  218. };
  219. static char *RemoteStartStopStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Rejected)
  222. };
  223. static char *ReservationStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Faulted),
  226. MACROSTR(Occupied),
  227. MACROSTR(Rejected),
  228. MACROSTR(Unavailable)
  229. };
  230. static char *ResetTypeStr[] = {
  231. MACROSTR(Hard),
  232. MACROSTR(Soft)
  233. };
  234. static char *ResetStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected)
  237. };
  238. static char * DiagnosticsStatusStr[] = {
  239. MACROSTR(Idle),
  240. MACROSTR(Uploaded),
  241. MACROSTR(UploadFailed),
  242. MACROSTR(Uploading)
  243. };
  244. static char * FirmwareStatusStr[] = {
  245. MACROSTR(Downloaded),
  246. MACROSTR(DownloadFailed),
  247. MACROSTR(Downloading),
  248. MACROSTR(Idle),
  249. MACROSTR(InstallationFailed),
  250. MACROSTR(Installing),
  251. MACROSTR(Installed)
  252. };
  253. static char * MessageTriggerStr[] = {
  254. MACROSTR(BootNotification),
  255. MACROSTR(DiagnosticsStatusNotification),
  256. MACROSTR(FirmwareStatusNotification),
  257. MACROSTR(Heartbeat),
  258. MACROSTR(MeterValues),
  259. MACROSTR(StatusNotification)
  260. };
  261. static char * TriggerMessageStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Rejected),
  264. MACROSTR(NotImplemented)
  265. };
  266. static char * UnlockStatusStr[] = {
  267. MACROSTR(Unlocked),
  268. MACROSTR(UnlockFailed),
  269. MACROSTR(NotSupported)
  270. };
  271. #if 0
  272. static char * StopTransactionReasonStr[] = {
  273. MACROSTR(EmergencyStop),
  274. MACROSTR(EVDisconnected),
  275. MACROSTR(HardReset),
  276. MACROSTR(Local),
  277. MACROSTR(Other),
  278. MACROSTR(PowerLoss),
  279. MACROSTR(Reboot),
  280. MACROSTR(Remote),
  281. MACROSTR(SoftReset),
  282. MACROSTR(UnlockCommand),
  283. MACROSTR(DeAuthorized)
  284. };
  285. #endif
  286. static char * CancelReservationStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected)
  289. };
  290. static char * ReadingContextStr[] = {
  291. MACROSTR(Interruption.Begin),
  292. MACROSTR(Interruption.End),
  293. MACROSTR(Other),
  294. MACROSTR(Sample.Clock),
  295. MACROSTR(Sample.Periodic),
  296. MACROSTR(Transaction.Begin),
  297. MACROSTR(Transaction.End),
  298. MACROSTR(Trigger)
  299. };
  300. static char * ValueFormatStr[] = {
  301. MACROSTR(Raw),
  302. MACROSTR(SignedData)
  303. };
  304. static char * MeasurandStr[] = {
  305. MACROSTR(Current.Export),
  306. MACROSTR(Current.Import),
  307. MACROSTR(Current.Offered),
  308. MACROSTR(Energy.Active.Export.Register),
  309. MACROSTR(Energy.Active.Import.Register),
  310. MACROSTR(Energy.Reactive.Export.Register),
  311. MACROSTR(Energy.Reactive.Import.Register),
  312. MACROSTR(Energy.Active.Export.Interval),
  313. MACROSTR(Energy.Active.Import.Interval),
  314. MACROSTR(Energy.Reactive.Export.Interval),
  315. MACROSTR(Energy.Reactive.Import.Interval),
  316. MACROSTR(Frequency),
  317. MACROSTR(Power.Active.Export),
  318. MACROSTR(Power.Active.Import),
  319. MACROSTR(Power.Factor),
  320. MACROSTR(Power.Offered),
  321. MACROSTR(Power.Reactive.ExportMACROSTR),
  322. MACROSTR(Power.Reactive.Import),
  323. MACROSTR(RPM),
  324. MACROSTR(SoC),
  325. MACROSTR(Temperature),
  326. MACROSTR(Voltage)
  327. };
  328. static char * LocationStr[] = {
  329. MACROSTR(Body),
  330. MACROSTR(Cable),
  331. MACROSTR(EV),
  332. MACROSTR(Inlet),
  333. MACROSTR(Outlet)
  334. };
  335. static char * PhaseStr[] = {
  336. MACROSTR(L1),
  337. MACROSTR(L2),
  338. MACROSTR(L3),
  339. MACROSTR(N),
  340. MACROSTR(L1-N),
  341. MACROSTR(L2-N),
  342. MACROSTR(L3-N),
  343. MACROSTR(L1-L2),
  344. MACROSTR(L2-L3),
  345. MACROSTR(L3-L1)
  346. };
  347. static char * UnitOfMeasureStr[] = {
  348. MACROSTR(Wh),
  349. MACROSTR(kWh),
  350. MACROSTR(varh),
  351. MACROSTR(kvarh),
  352. MACROSTR(W),
  353. MACROSTR(kW),
  354. MACROSTR(VA),
  355. MACROSTR(kVA),
  356. MACROSTR(var),
  357. MACROSTR(kvar),
  358. MACROSTR(A),
  359. MACROSTR(V),
  360. MACROSTR(Celsius),
  361. MACROSTR(Fahrenheit),
  362. MACROSTR(K),
  363. MACROSTR(Percent)
  364. };
  365. //=========================================
  366. // TTIA routine
  367. //=========================================
  368. int sendTTIAInfo(uint8_t gun_index)
  369. {
  370. static int sn = 0;
  371. int result = FAIL;
  372. struct hostent *server;
  373. int udp_socket_fd;
  374. struct sockaddr_in dest_addr = {0};
  375. uint8_t tx_buf[80] = {0};
  376. uint8_t logBuf[256]= {0};
  377. uint8_t tx_len, tempIndex, socStart, socEnd;
  378. uint16_t PresentChargedEnergy;
  379. struct tm tmStart, tmEnd;
  380. DEBUG_INFO("sendTTIAInfo...\n");
  381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  382. {
  383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  384. {
  385. tempIndex = ((gun_index==2) ? 1: 0);
  386. }
  387. else
  388. {
  389. tempIndex = gun_index;
  390. }
  391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  392. {
  393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  394. {
  395. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  396. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  397. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  398. }
  399. }
  400. }
  401. else if(gunType[gun_index] == GUN_TYPE_CCS)
  402. {
  403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  404. {
  405. tempIndex = ((gun_index==2) ? 1: 0);
  406. }
  407. else
  408. {
  409. tempIndex = gun_index;
  410. }
  411. for (int index = 0; index < CCS_QUANTITY; index++)
  412. {
  413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  414. {
  415. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  416. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  417. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  418. }
  419. }
  420. }
  421. else if(gunType[gun_index] == GUN_TYPE_GBT)
  422. {
  423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  424. {
  425. tempIndex = ((gun_index==2) ? 1: 0);
  426. }
  427. else
  428. {
  429. tempIndex = gun_index;
  430. }
  431. for (int index = 0; index < GB_QUANTITY; index++)
  432. {
  433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  434. {
  435. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  436. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  437. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  438. }
  439. }
  440. }
  441. else if(gunType[gun_index] == GUN_TYPE_DO)
  442. {
  443. tempIndex = gun_index;
  444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  445. {
  446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  447. {
  448. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  449. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  450. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  451. }
  452. }
  453. }
  454. else
  455. {
  456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  457. {
  458. tempIndex = 2;
  459. }
  460. else
  461. {
  462. tempIndex = gun_index;
  463. }
  464. for (int index = 0; index < AC_QUANTITY; index++)
  465. {
  466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  467. {
  468. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  469. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  470. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  471. }
  472. }// END
  473. }
  474. // Message assembly
  475. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  476. tx_buf[4] = 0x02; // Protocol Version
  477. tx_buf[5] = 0xb0; // Message ID
  478. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  479. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  480. tx_buf[8] = 0x00; // CarID low byte
  481. tx_buf[9] = 0x00; // CarID high byte
  482. tx_buf[10] = 0x00; // ID Storage
  483. tx_buf[11] = 0x00; // Driver lowest byte
  484. tx_buf[12] = 0x00; // Driver 2nd byte
  485. tx_buf[13] = 0x00; // Driver 3rd byte
  486. tx_buf[14] = 0x00; // Driver highest byte
  487. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  488. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  489. tx_buf[17] = 0x00; // Reserve
  490. tx_buf[18] = 60 & 0xff; // Payload length low byte
  491. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  492. // EVSE provider
  493. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  494. // EVSE provider
  495. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  496. // EVSE id
  497. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  498. // Connector id
  499. tx_buf[37] = gun_index;
  500. // EVSE station
  501. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  502. // Vehicle SN
  503. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  504. // Mileage
  505. tx_buf[61] = 0x00; // lowest byte
  506. tx_buf[62] = 0x00; // 2nd byte
  507. tx_buf[63] = 0x00; // highest byte
  508. // Start date time 6 bytes
  509. 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))
  510. {
  511. struct tm *tmTarget;
  512. struct timeb tbTarget;
  513. tmStart.tm_year -= 1900;
  514. tmStart.tm_mon -= 1;
  515. tmStart.tm_gmtoff = 0;
  516. tbTarget.time = mktime(&tmStart);
  517. tbTarget.timezone = 0;
  518. tbTarget.time += (8*3600);
  519. tmTarget = gmtime(&tbTarget.time);
  520. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  521. tx_buf[65] = (tmTarget->tm_mon+1);
  522. tx_buf[66] = tmTarget->tm_mday;
  523. tx_buf[67] = tmTarget->tm_hour;
  524. tx_buf[68] = tmTarget->tm_min;
  525. tx_buf[69] = tmTarget->tm_sec;
  526. }
  527. // Stop date time 6 bytes
  528. 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))
  529. {
  530. struct tm *tmTarget;
  531. struct timeb tbTarget;
  532. tmEnd.tm_year -= 1900;
  533. tmEnd.tm_mon -= 1;
  534. tmEnd.tm_gmtoff = 0;
  535. tbTarget.time = mktime(&tmEnd);
  536. tbTarget.timezone = 0;
  537. tbTarget.time += (8*3600);
  538. tmTarget = gmtime(&tbTarget.time);
  539. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  540. tx_buf[71] = (tmTarget->tm_mon+1);
  541. tx_buf[72] = tmTarget->tm_mday;
  542. tx_buf[73] = tmTarget->tm_hour;
  543. tx_buf[74] = tmTarget->tm_min;
  544. tx_buf[75] = tmTarget->tm_sec;
  545. }
  546. // Session energy 2 bytes
  547. tx_buf[76] = PresentChargedEnergy & 0xff;
  548. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  549. // Start SOC 1 byte
  550. tx_buf[78] = socStart;
  551. // Stop SOC 1 byte
  552. tx_buf[79] = socEnd;
  553. // Open socket
  554. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  555. if(udp_socket_fd == -1)
  556. {
  557. DEBUG_ERROR("UDP socket create failed!\n");
  558. }
  559. else
  560. {
  561. // Get server DNS entry
  562. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  563. if (server == NULL)
  564. {
  565. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  566. }
  567. else
  568. {
  569. // Build the server's Internet address
  570. bzero((char *) &dest_addr, sizeof(dest_addr));
  571. dest_addr.sin_family = AF_INET;
  572. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  573. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  575. {
  576. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  577. {
  578. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  579. }
  580. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  581. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  582. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  583. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  584. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  585. DEBUG_TTIA_INFO("---------- Header ----------\n");
  586. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  587. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  588. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  589. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  590. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  591. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  592. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  593. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  594. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  595. DEBUG_TTIA_INFO("Len: 0x3C\n");
  596. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  597. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  598. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  599. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  600. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  601. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  602. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  603. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  604. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  605. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  606. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  607. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  608. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  609. DEBUG_TTIA_INFO("=========================================\n");
  610. sn++;
  611. result = PASS;
  612. }
  613. else
  614. {
  615. DEBUG_ERROR("UDP sent out fail.\n");
  616. }
  617. }
  618. }
  619. return result;
  620. }
  621. //=========================================
  622. // Save configuration
  623. //=========================================
  624. int runShellCmd(const char*cmd)
  625. {
  626. int result = FAIL;
  627. char buf[256];
  628. FILE *fp;
  629. fp = popen(cmd, "r");
  630. if(fp != NULL)
  631. {
  632. while(fgets(buf, sizeof(buf), fp) != NULL)
  633. {
  634. DEBUG_INFO("%s\n", buf);
  635. }
  636. result = PASS;
  637. }
  638. pclose(fp);
  639. return result;
  640. }
  641. int StoreUsrConfigData(struct SysConfigData *UsrData)
  642. {
  643. int result = PASS;
  644. int fd,wrd;
  645. unsigned int i,Chk;
  646. unsigned char *ptr, *BufTmp;
  647. int MtdBlockSize = 0x300000;
  648. Chk=0;
  649. ptr=(unsigned char *)UsrData;
  650. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  651. {
  652. memset(BufTmp,0,MtdBlockSize);
  653. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  654. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  655. Chk+=*(BufTmp+i);
  656. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  657. // Output configuration to file.
  658. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  659. if (fd < 0)
  660. {
  661. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  662. free(BufTmp);
  663. return 0;
  664. }
  665. wrd=write(fd, BufTmp, MtdBlockSize);
  666. close(fd);
  667. if(wrd<MtdBlockSize)
  668. {
  669. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  670. free(BufTmp);
  671. return 0;
  672. }
  673. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  674. DEBUG_INFO("Erase /dev/mtd10.\n");
  675. runShellCmd("flash_erase /dev/mtd10 0 0");
  676. DEBUG_INFO("Write /dev/mtd10.\n");
  677. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  678. DEBUG_INFO("Erase /dev/mtd11.\n");
  679. runShellCmd("flash_erase /dev/mtd11 0 0");
  680. DEBUG_INFO("Write /dev/mtd11.\n");
  681. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  682. system("rm -f /mnt/EvseConfig.bin");
  683. DEBUG_INFO("EvseConfig write to flash OK\n");
  684. }
  685. else
  686. {
  687. DEBUG_ERROR("alloc BlockSize NG\r\n");
  688. result = FAIL;
  689. }
  690. if(BufTmp!=NULL)
  691. free(BufTmp);
  692. return result;
  693. }
  694. //=========================================
  695. // Sqlite3 related function
  696. //=========================================
  697. static int selectSqlCount = 0;
  698. static int callback(void *data, int argc, char **argv, char **azColName){
  699. int i;
  700. //printf("%s: ", (const char*)data);
  701. selectSqlCount = argc;
  702. for(i = 0; i<argc; i++){
  703. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  704. }
  705. //printf("\n");
  706. return 0;
  707. }
  708. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  709. //int i;
  710. //printf("%s:\n", (const char*)data);
  711. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  712. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  713. return 0;
  714. }
  715. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  716. //printf("%s:\n", (const char*)data);
  717. //idTag
  718. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  719. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  720. //parentIdTag
  721. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  722. //expir_date
  723. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  724. //status
  725. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  726. //version
  727. if(columenCount > 5)
  728. idTagQuery.listVersionInt = atoi(columnValue[5]);
  729. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  730. return 0;
  731. }
  732. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  733. {
  734. // localversion = argv[5] ? atoi(argv[5]) : 0;
  735. // printf("localversion=%d\n", localversion);
  736. return 0;
  737. }
  738. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  739. {
  740. for (int i = 0; i < n_columns; i++)
  741. {
  742. DEBUG_INFO("%s\t", col_values[i]);
  743. }
  744. DEBUG_INFO("\n");
  745. return 0;
  746. }
  747. int OCPP_cleanLocalCache()
  748. {
  749. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  750. char *errMsg = 0;
  751. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  752. if (SQLITE_OK != rc)
  753. {
  754. DEBUG_INFO("SQL error: %s\n",errMsg);
  755. return FALSE;
  756. }
  757. return TRUE;
  758. }
  759. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  760. {
  761. int isSuccess = TRUE;
  762. int ret = 0;
  763. //const char* data = "Callback function called";
  764. char sql[300];
  765. char zErrMsg[200];
  766. memset(sql, 0, 300);
  767. memset(zErrMsg, 0, 200);
  768. 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);
  769. //* Execute SQL statement */
  770. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  771. if( ret != SQLITE_OK )
  772. {
  773. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  774. isSuccess = FALSE;
  775. }
  776. return isSuccess;
  777. }
  778. void OCPP_getIdTagFromLocalCache(char idTag[])
  779. {
  780. int rc = 0;
  781. char sql[100];
  782. char zErrMsg[100];
  783. memset(sql, 0, 100);
  784. memset(zErrMsg, 0, 100);
  785. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  786. memset(&idTagQuery, 0, sizeof(idTagQuery));
  787. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  788. /* Execute SQL statement */
  789. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  790. if( rc != SQLITE_OK )
  791. {
  792. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  793. }
  794. }
  795. void OCPP_getListVerion()
  796. {
  797. int rc = 0;
  798. // const char* data = "Callback function called";
  799. char sql[100];
  800. char zErrMsg[100];
  801. memset(sql, 0, 100);
  802. memset(zErrMsg, 0, 100);
  803. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  804. /* Execute SQL statement */
  805. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  806. if( rc != SQLITE_OK )
  807. {
  808. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  809. }
  810. }
  811. void OCPP_get_TableAuthlocalAllData(void)
  812. {
  813. int rc = 0;
  814. char sql[100];
  815. char zErrMsg[100];
  816. memset(sql, 0, 100);
  817. memset(zErrMsg, 0, 100);
  818. sprintf(sql,"select * from ocpp_auth_local ");
  819. /* Execute SQL statement */
  820. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  821. if( rc != SQLITE_OK )
  822. {
  823. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  824. }
  825. //return ver;
  826. }
  827. int OCPP_cleanLocalList()
  828. {
  829. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  830. char *errMsg = 0;
  831. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  832. if (SQLITE_OK != rc)
  833. {
  834. DEBUG_INFO("%s\n",errMsg);
  835. return FALSE;
  836. }
  837. return TRUE;
  838. }
  839. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  840. {
  841. int isSuccess = FALSE;
  842. int ret = 0;
  843. //const char* data = "Callback function called";
  844. char sql[300];
  845. char zErrMsg[200];
  846. memset(sql, 0, 300);
  847. memset(zErrMsg, 0, 200);
  848. 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);
  849. //* Execute SQL statement */
  850. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  851. if( ret != SQLITE_OK )
  852. {
  853. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  854. return isSuccess;
  855. }
  856. memset(sql, 0, 300);
  857. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  858. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  859. if( ret != SQLITE_OK )
  860. {
  861. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  862. return isSuccess;
  863. }
  864. isSuccess = TRUE;
  865. return isSuccess;
  866. }
  867. void OCPP_getIdTagFromLocalList(char idTag[])
  868. {
  869. int rc = 0;
  870. // const char* data = "Callback function called";
  871. char sql[100];
  872. char zErrMsg[100];
  873. memset(sql, 0, 100);
  874. memset(zErrMsg, 0, 100);
  875. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  876. memset(&idTagQuery, 0, sizeof(idTagQuery));
  877. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  878. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  879. /* Execute SQL statement */
  880. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  881. if( rc != SQLITE_OK )
  882. {
  883. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  884. }
  885. //return ver;
  886. }
  887. void OCPP_deleteIdTagFromLocalList(char idTag[])
  888. {
  889. //int ver = 0;
  890. //int isSuccess = FALSE;
  891. int rc = 0;
  892. char sql[100];
  893. char zErrMsg[100];
  894. memset(sql, 0, 100);
  895. memset(zErrMsg, 0, 100);
  896. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  897. //* Execute SQL statement */
  898. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  899. if( rc != SQLITE_OK )
  900. {
  901. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  902. }
  903. }
  904. int getCurrentYear()
  905. {
  906. int result = 0;
  907. time_t CurrentTime;
  908. struct tm *tm;
  909. CurrentTime = time(NULL);
  910. tm=localtime(&CurrentTime);
  911. result = (tm->tm_year + 1900);
  912. return result;
  913. }
  914. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  915. {
  916. int result = PASS;
  917. char* errMsg = NULL;
  918. char sqlStr[8192];
  919. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  920. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  921. {
  922. result = FAIL;
  923. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  924. }
  925. 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));
  926. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  927. {
  928. result = FAIL;
  929. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  930. }
  931. return result;
  932. }
  933. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  934. {
  935. int isSuccess = TRUE;
  936. int tempIndex;
  937. json_object *EnergyDataTransfer = json_object_new_object();
  938. json_object *periodEnergys = json_object_new_object();
  939. char sql[1024];
  940. char zErrMsg[200];
  941. memset(sql, 0, ARRAY_SIZE(sql));
  942. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  944. {
  945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  946. {
  947. tempIndex = ((gun_index==2) ? 1: 0);
  948. }
  949. else
  950. {
  951. tempIndex = gun_index;
  952. }
  953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  954. {
  955. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  956. {
  957. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  958. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  959. {
  960. uint8_t period[3];
  961. sprintf((char*)period, "%d", idxPeriod);
  962. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  963. }
  964. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  965. } //end of the same index
  966. }//end of for CHAdeMO_QUANTITY
  967. }
  968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  969. {
  970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  971. {
  972. tempIndex = ((gun_index==2) ? 1: 0);
  973. }
  974. else
  975. {
  976. tempIndex = gun_index;
  977. }
  978. for (int index = 0; index < CCS_QUANTITY; index++)
  979. {
  980. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  981. {
  982. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  983. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  984. {
  985. uint8_t period[3];
  986. sprintf((char*)period, "%d", idxPeriod);
  987. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  988. }
  989. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  990. } //end of the same index
  991. } // end of for CCS_QUANTITY
  992. }
  993. else if(gunType[gun_index] == GUN_TYPE_GBT)
  994. {
  995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  996. {
  997. tempIndex = ((gun_index==2) ? 1: 0);
  998. }
  999. else
  1000. {
  1001. tempIndex = gun_index;
  1002. }
  1003. for (int index = 0; index < GB_QUANTITY; index++)
  1004. {
  1005. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1006. {
  1007. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1008. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1009. {
  1010. uint8_t period[3];
  1011. sprintf((char*)period, "%d", idxPeriod);
  1012. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1013. }
  1014. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1015. } //end of the same index
  1016. } // end of for GB_QUANTITY
  1017. }
  1018. else if(gunType[gun_index] == GUN_TYPE_DO)
  1019. {
  1020. tempIndex = gun_index;
  1021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1022. {
  1023. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1024. {
  1025. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1026. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1027. {
  1028. uint8_t period[3];
  1029. sprintf((char*)period, "%d", idxPeriod);
  1030. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1031. }
  1032. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1033. } //end of the same index
  1034. }
  1035. }
  1036. else
  1037. {
  1038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1039. {
  1040. tempIndex = 2;
  1041. }
  1042. else
  1043. {
  1044. tempIndex = gun_index;
  1045. }
  1046. for (int index = 0; index < AC_QUANTITY; index++)
  1047. {
  1048. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1049. {
  1050. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1051. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1052. {
  1053. uint8_t period[3];
  1054. sprintf((char*)period, "%d", idxPeriod);
  1055. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1056. }
  1057. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1058. }//end of the same index
  1059. }//end of for AC_QUANTITY
  1060. }
  1061. 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));
  1062. json_object_put(EnergyDataTransfer);
  1063. //* Execute SQL statement */
  1064. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1065. {
  1066. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1067. isSuccess = FALSE;
  1068. }
  1069. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1070. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1071. {
  1072. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1073. isSuccess = FALSE;
  1074. }
  1075. return isSuccess;
  1076. }
  1077. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1078. {
  1079. int isSuccess = TRUE;
  1080. char sql[512];
  1081. char zErrMsg[200];
  1082. int rows, cols;
  1083. char **resultData;
  1084. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1085. /* Execute SQL statement */
  1086. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1087. {
  1088. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1089. isSuccess = FALSE;
  1090. }
  1091. else
  1092. {
  1093. if((rows > 0) && (atoi(resultData[4]) > 0))
  1094. {
  1095. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1096. }
  1097. else
  1098. {
  1099. DEBUG_WARN("There is not match transaction data.\n");
  1100. isSuccess = FALSE;
  1101. }
  1102. }
  1103. return isSuccess;
  1104. }
  1105. 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)
  1106. {
  1107. int result = PASS;
  1108. char* errMsg = NULL;
  1109. char sqlStr[8192];
  1110. 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');",
  1111. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1112. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1113. {
  1114. result = FAIL;
  1115. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1116. }
  1117. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1118. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1119. {
  1120. result = FAIL;
  1121. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1122. }
  1123. return result;
  1124. }
  1125. int OCPP_update_deduct_info(int txId, char *creditNo)
  1126. {
  1127. int result = PASS;
  1128. char* errMsg = NULL;
  1129. char sqlStr[8192];
  1130. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1131. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1132. {
  1133. result = FAIL;
  1134. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1135. }
  1136. return result;
  1137. }
  1138. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1139. {
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1143. atoi(columnValue[1]),
  1144. columnValue[2],
  1145. atoi(columnValue[3])==1?"true":"false",
  1146. atoi(columnValue[4])==1?"true":"false",
  1147. columnValue[5],
  1148. columnValue[9]);
  1149. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1150. return 0;
  1151. }
  1152. void OCPP_query_deduct_info()
  1153. {
  1154. int rc = 0;
  1155. char sql[100];
  1156. char zErrMsg[100];
  1157. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1158. /* Execute SQL statement */
  1159. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1160. if( rc != SQLITE_OK )
  1161. {
  1162. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1163. }
  1164. }
  1165. void reportReaderStatus(int gun_index)
  1166. {
  1167. struct timeval tmnow;
  1168. struct tm *tm;
  1169. char buf[28];//, usec_buf[6];
  1170. gettimeofday(&tmnow, NULL);
  1171. time_t t;
  1172. t = time(NULL);
  1173. /*UTC time and date*/
  1174. tm = gmtime(&t);
  1175. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1176. #if 0 // remove temporally
  1177. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1178. strcat(buf,".");
  1179. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1180. strcat(buf,usec_buf);
  1181. #endif
  1182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1185. (gun_index+1),
  1186. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1187. buf,
  1188. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1189. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1190. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1191. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1192. }
  1193. //==========================================
  1194. // Check time passed since today
  1195. //==========================================
  1196. long long DiffTimebWithNow(struct timeb ST)
  1197. {
  1198. //return milli-second
  1199. struct timeb ET;
  1200. long long StartTime,StopTime;
  1201. ftime(&ET);
  1202. StartTime=(long long)ST.time;
  1203. StopTime=(long long)ET.time;
  1204. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1205. }
  1206. int getTimePassSinceToday(uint8_t gun_index)
  1207. {
  1208. int result = -1;
  1209. static time_t lastTime[4];
  1210. time_t t;
  1211. struct tm *tmStartToday;
  1212. struct timeb tbStartToday;
  1213. t=time(NULL);
  1214. if(difftime(t, lastTime[gun_index])>0)
  1215. {
  1216. tmStartToday=localtime(&t);
  1217. tmStartToday->tm_hour = 0;
  1218. tmStartToday->tm_min = 0;
  1219. tmStartToday->tm_sec = 0;
  1220. tbStartToday.time = mktime(tmStartToday);
  1221. tbStartToday.millitm = 0;
  1222. result = DiffTimebWithNow(tbStartToday)/1000;
  1223. lastTime[gun_index] = t;
  1224. }
  1225. return result;
  1226. }
  1227. void getNowDatetime(uint8_t *data)
  1228. {
  1229. time_t t = time(NULL);
  1230. struct tm tm = *localtime(&t);
  1231. 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);
  1232. }
  1233. int syncDateTimeRTC(uint8_t *data)
  1234. {
  1235. struct ParsingResult
  1236. {
  1237. int result;
  1238. int scanedElement;
  1239. int year;
  1240. int month;
  1241. int mday;
  1242. int hour;
  1243. int min;
  1244. int sec;
  1245. int tz_hour;
  1246. int tz_min;
  1247. float minSec;
  1248. }result;
  1249. struct tm tmOrg;
  1250. struct tm *tmTarget;
  1251. struct timeb tbTarget;
  1252. char buf[128];
  1253. memset(&result, 0x00, sizeof(struct ParsingResult));
  1254. result.result = PASS;
  1255. if(strstr((char*)data, ".") != NULL)
  1256. {
  1257. // Original data with mini second
  1258. if(strstr((char*)data, "Z") != NULL)
  1259. {
  1260. // Original data with Z
  1261. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1262. &result.year,
  1263. &result.month,
  1264. &result.mday,
  1265. &result.hour,
  1266. &result.min,
  1267. &result.sec,
  1268. &result.minSec);
  1269. }
  1270. else
  1271. {
  1272. // Original data without Z
  1273. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1274. &result.year,
  1275. &result.month,
  1276. &result.mday,
  1277. &result.hour,
  1278. &result.min,
  1279. &result.sec,
  1280. &result.minSec,
  1281. &result.tz_hour,
  1282. &result.tz_min);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. // Original data without mini second
  1288. if(strstr((char*)data, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1292. &result.year,
  1293. &result.month,
  1294. &result.mday,
  1295. &result.hour,
  1296. &result.min,
  1297. &result.sec);
  1298. }
  1299. else
  1300. {
  1301. // Original data without Z
  1302. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1303. &result.year,
  1304. &result.month,
  1305. &result.mday,
  1306. &result.hour,
  1307. &result.min,
  1308. &result.sec,
  1309. &result.tz_hour,
  1310. &result.tz_min);
  1311. }
  1312. }
  1313. tmOrg.tm_year = result.year - 1900;
  1314. tmOrg.tm_mon = result.month - 1;
  1315. tmOrg.tm_mday = result.mday;
  1316. tmOrg.tm_hour = result.hour;
  1317. tmOrg.tm_min = result.min;
  1318. tmOrg.tm_sec = result.sec;
  1319. tmOrg.tm_gmtoff = 0;
  1320. tbTarget.time = mktime(&tmOrg);
  1321. tbTarget.timezone = 0;
  1322. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1323. tmTarget = gmtime(&tbTarget.time);
  1324. 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);
  1325. //DEBUG_INFO(" org date time: %s\n", data);
  1326. //DEBUG_INFO("parse date time: %s\n", buf);
  1327. system(buf);
  1328. system("/sbin/hwclock -w --systohc");
  1329. if(result.scanedElement < 6)
  1330. result.result = FAIL;
  1331. return result.result;
  1332. }
  1333. //==========================================
  1334. // GetCompositeSchedule logic related function
  1335. //==========================================
  1336. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1337. {
  1338. //return milli-second
  1339. unsigned int StartTime,StopTime;
  1340. StartTime=(unsigned int)ST.time;
  1341. StopTime=(unsigned int)ET.time;
  1342. return (StopTime-StartTime);
  1343. }
  1344. int DiffTimebWithNowSec(struct timeb ST)
  1345. {
  1346. //return milli-second
  1347. struct timeb ET;
  1348. unsigned int StartTime,StopTime;
  1349. ftime(&ET);
  1350. StartTime=(unsigned int)ST.time;
  1351. StopTime=(unsigned int)ET.time;
  1352. return (StopTime-StartTime);
  1353. }
  1354. int getStartStop(uint8_t *start, uint8_t *stop)
  1355. {
  1356. struct ParsingResult
  1357. {
  1358. int result;
  1359. int scanedElement;
  1360. int year;
  1361. int month;
  1362. int mday;
  1363. int hour;
  1364. int min;
  1365. int sec;
  1366. int tz_hour;
  1367. int tz_min;
  1368. float minSec;
  1369. };
  1370. struct ParsingResult parseStart;
  1371. struct ParsingResult parseStop;
  1372. int result = -1;
  1373. struct tm tmStart;
  1374. struct timeb tbStart;
  1375. struct tm tmStop;
  1376. struct timeb tbStop;
  1377. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1378. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1379. // Scan start & stop date time
  1380. if(strstr((char*)start, ".") != NULL)
  1381. {
  1382. // Original data with mini second
  1383. if(strstr((char*)start, "Z") != NULL)
  1384. {
  1385. // Original data with Z
  1386. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1387. &parseStart.year,
  1388. &parseStart.month,
  1389. &parseStart.mday,
  1390. &parseStart.hour,
  1391. &parseStart.min,
  1392. &parseStart.sec,
  1393. &parseStart.minSec);
  1394. }
  1395. else
  1396. {
  1397. // Original data without Z
  1398. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1399. &parseStart.year,
  1400. &parseStart.month,
  1401. &parseStart.mday,
  1402. &parseStart.hour,
  1403. &parseStart.min,
  1404. &parseStart.sec,
  1405. &parseStart.minSec,
  1406. &parseStart.tz_hour,
  1407. &parseStart.tz_min);
  1408. }
  1409. }
  1410. else
  1411. {
  1412. // Original data without mini second
  1413. if(strstr((char*)start, "Z") != NULL)
  1414. {
  1415. // Original data with Z
  1416. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1417. &parseStart.year,
  1418. &parseStart.month,
  1419. &parseStart.mday,
  1420. &parseStart.hour,
  1421. &parseStart.min,
  1422. &parseStart.sec);
  1423. }
  1424. else
  1425. {
  1426. // Original data without Z
  1427. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1428. &parseStart.year,
  1429. &parseStart.month,
  1430. &parseStart.mday,
  1431. &parseStart.hour,
  1432. &parseStart.min,
  1433. &parseStart.sec,
  1434. &parseStart.tz_hour,
  1435. &parseStart.tz_min);
  1436. }
  1437. }
  1438. if(strstr((char*)stop, ".") != NULL)
  1439. {
  1440. // Original data with mini second
  1441. if(strstr((char*)stop, "Z") != NULL)
  1442. {
  1443. // Original data with Z
  1444. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1445. &parseStop.year,
  1446. &parseStop.month,
  1447. &parseStop.mday,
  1448. &parseStop.hour,
  1449. &parseStop.min,
  1450. &parseStop.sec,
  1451. &parseStop.minSec);
  1452. }
  1453. else
  1454. {
  1455. // Original data without Z
  1456. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1457. &parseStop.year,
  1458. &parseStop.month,
  1459. &parseStop.mday,
  1460. &parseStop.hour,
  1461. &parseStop.min,
  1462. &parseStop.sec,
  1463. &parseStop.minSec,
  1464. &parseStop.tz_hour,
  1465. &parseStop.tz_min);
  1466. }
  1467. }
  1468. else
  1469. {
  1470. // Original data without mini second
  1471. if(strstr((char*)stop, "Z") != NULL)
  1472. {
  1473. // Original data with Z
  1474. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1475. &parseStop.year,
  1476. &parseStop.month,
  1477. &parseStop.mday,
  1478. &parseStop.hour,
  1479. &parseStop.min,
  1480. &parseStop.sec);
  1481. }
  1482. else
  1483. {
  1484. // Original data without Z
  1485. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1486. &parseStop.year,
  1487. &parseStop.month,
  1488. &parseStop.mday,
  1489. &parseStop.hour,
  1490. &parseStop.min,
  1491. &parseStop.sec,
  1492. &parseStop.tz_hour,
  1493. &parseStop.tz_min);
  1494. }
  1495. }
  1496. // Calculate date time difference
  1497. if((parseStart.scanedElement >=6) &&
  1498. (parseStop.scanedElement >=6))
  1499. {
  1500. //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);
  1501. //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);
  1502. tmStart.tm_year = parseStart.year - 1900;
  1503. tmStart.tm_mon = parseStart.month - 1;
  1504. tmStart.tm_mday = parseStart.mday;
  1505. tmStart.tm_hour = parseStart.hour;
  1506. tmStart.tm_min = parseStart.min;
  1507. tmStart.tm_sec = parseStart.sec;
  1508. tmStart.tm_gmtoff = 0;
  1509. tbStart.time = mktime(&tmStart);
  1510. tbStart.timezone = 0;
  1511. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1512. tmStop.tm_year = parseStop.year - 1900;
  1513. tmStop.tm_mon = parseStop.month - 1;
  1514. tmStop.tm_mday = parseStop.mday;
  1515. tmStop.tm_hour = parseStop.hour;
  1516. tmStop.tm_min = parseStop.min;
  1517. tmStop.tm_sec = parseStop.sec;
  1518. tmStop.tm_gmtoff = 0;
  1519. tbStop.time = mktime(&tmStop);
  1520. tbStop.timezone = 0;
  1521. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1522. result = DiffTimebSec(tbStart, tbStop);
  1523. //DEBUG_INFO("getStartStop(): %d\n", result);
  1524. }
  1525. else
  1526. {
  1527. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1528. }
  1529. return result;
  1530. }
  1531. int isOvertNow(uint8_t *start)
  1532. {
  1533. int result = NO;
  1534. struct ParsingResult
  1535. {
  1536. int result;
  1537. int scanedElement;
  1538. int year;
  1539. int month;
  1540. int mday;
  1541. int hour;
  1542. int min;
  1543. int sec;
  1544. int tz_hour;
  1545. int tz_min;
  1546. float minSec;
  1547. }parsingResult;
  1548. struct tm tmStart;
  1549. struct timeb tbStart;
  1550. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1551. if(strstr((char*)start, ".") != NULL)
  1552. {
  1553. // Original data with mini second
  1554. if(strstr((char*)start, "Z") != NULL)
  1555. {
  1556. // Original data with Z
  1557. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1558. &parsingResult.year,
  1559. &parsingResult.month,
  1560. &parsingResult.mday,
  1561. &parsingResult.hour,
  1562. &parsingResult.min,
  1563. &parsingResult.sec,
  1564. &parsingResult.minSec);
  1565. }
  1566. else
  1567. {
  1568. // Original data without Z
  1569. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1570. &parsingResult.year,
  1571. &parsingResult.month,
  1572. &parsingResult.mday,
  1573. &parsingResult.hour,
  1574. &parsingResult.min,
  1575. &parsingResult.sec,
  1576. &parsingResult.minSec,
  1577. &parsingResult.tz_hour,
  1578. &parsingResult.tz_min);
  1579. }
  1580. }
  1581. else
  1582. {
  1583. // Original data without mini second
  1584. if(strstr((char*)start, "Z") != NULL)
  1585. {
  1586. // Original data with Z
  1587. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1588. &parsingResult.year,
  1589. &parsingResult.month,
  1590. &parsingResult.mday,
  1591. &parsingResult.hour,
  1592. &parsingResult.min,
  1593. &parsingResult.sec);
  1594. }
  1595. else
  1596. {
  1597. // Original data without Z
  1598. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1599. &parsingResult.year,
  1600. &parsingResult.month,
  1601. &parsingResult.mday,
  1602. &parsingResult.hour,
  1603. &parsingResult.min,
  1604. &parsingResult.sec,
  1605. &parsingResult.tz_hour,
  1606. &parsingResult.tz_min);
  1607. }
  1608. }
  1609. if(parsingResult.scanedElement >= 6)
  1610. {
  1611. tmStart.tm_year = parsingResult.year - 1900;
  1612. tmStart.tm_mon = parsingResult.month - 1;
  1613. tmStart.tm_mday = parsingResult.mday;
  1614. tmStart.tm_hour = parsingResult.hour;
  1615. tmStart.tm_min = parsingResult.min;
  1616. tmStart.tm_sec = parsingResult.sec;
  1617. tmStart.tm_gmtoff = 0;
  1618. tbStart.time = mktime(&tmStart);
  1619. tbStart.timezone = 0;
  1620. tbStart.millitm = 0;
  1621. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1622. if(DiffTimebWithNowSec(tbStart) <= 0)
  1623. result = NO;
  1624. else
  1625. result = YES;
  1626. }
  1627. else
  1628. {
  1629. DEBUG_WARN("Start date parsing error.\n");
  1630. }
  1631. return result;
  1632. }
  1633. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1634. {
  1635. struct ParsingResult
  1636. {
  1637. int result;
  1638. int scanedElement;
  1639. int year;
  1640. int month;
  1641. int mday;
  1642. int hour;
  1643. int min;
  1644. int sec;
  1645. int tz_hour;
  1646. int tz_min;
  1647. float minSec;
  1648. };
  1649. struct ParsingResult parseStart;
  1650. struct ParsingResult parseStop;
  1651. int result = -1;
  1652. struct tm tmStart;
  1653. struct timeb tbStart;
  1654. struct tm tmStop;
  1655. struct timeb tbStop;
  1656. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1657. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1658. // Scan start & stop date time
  1659. if(strstr((char*)start, ".") != NULL)
  1660. {
  1661. // Original data with mini second
  1662. if(strstr((char*)start, "Z") != NULL)
  1663. {
  1664. // Original data with Z
  1665. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1666. &parseStart.year,
  1667. &parseStart.month,
  1668. &parseStart.mday,
  1669. &parseStart.hour,
  1670. &parseStart.min,
  1671. &parseStart.sec,
  1672. &parseStart.minSec);
  1673. }
  1674. else
  1675. {
  1676. // Original data without Z
  1677. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1678. &parseStart.year,
  1679. &parseStart.month,
  1680. &parseStart.mday,
  1681. &parseStart.hour,
  1682. &parseStart.min,
  1683. &parseStart.sec,
  1684. &parseStart.minSec,
  1685. &parseStart.tz_hour,
  1686. &parseStart.tz_min);
  1687. }
  1688. }
  1689. else
  1690. {
  1691. // Original data without mini second
  1692. if(strstr((char*)start, "Z") != NULL)
  1693. {
  1694. // Original data with Z
  1695. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1696. &parseStart.year,
  1697. &parseStart.month,
  1698. &parseStart.mday,
  1699. &parseStart.hour,
  1700. &parseStart.min,
  1701. &parseStart.sec);
  1702. }
  1703. else
  1704. {
  1705. // Original data without Z
  1706. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1707. &parseStart.year,
  1708. &parseStart.month,
  1709. &parseStart.mday,
  1710. &parseStart.hour,
  1711. &parseStart.min,
  1712. &parseStart.sec,
  1713. &parseStart.tz_hour,
  1714. &parseStart.tz_min);
  1715. }
  1716. }
  1717. if(strstr((char*)stop, ".") != NULL)
  1718. {
  1719. // Original data with mini second
  1720. if(strstr((char*)stop, "Z") != NULL)
  1721. {
  1722. // Original data with Z
  1723. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1724. &parseStop.year,
  1725. &parseStop.month,
  1726. &parseStop.mday,
  1727. &parseStop.hour,
  1728. &parseStop.min,
  1729. &parseStop.sec,
  1730. &parseStop.minSec);
  1731. }
  1732. else
  1733. {
  1734. // Original data without Z
  1735. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1736. &parseStop.year,
  1737. &parseStop.month,
  1738. &parseStop.mday,
  1739. &parseStop.hour,
  1740. &parseStop.min,
  1741. &parseStop.sec,
  1742. &parseStop.minSec,
  1743. &parseStop.tz_hour,
  1744. &parseStop.tz_min);
  1745. }
  1746. }
  1747. else
  1748. {
  1749. // Original data without mini second
  1750. if(strstr((char*)stop, "Z") != NULL)
  1751. {
  1752. // Original data with Z
  1753. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1754. &parseStop.year,
  1755. &parseStop.month,
  1756. &parseStop.mday,
  1757. &parseStop.hour,
  1758. &parseStop.min,
  1759. &parseStop.sec);
  1760. }
  1761. else
  1762. {
  1763. // Original data without Z
  1764. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1765. &parseStop.year,
  1766. &parseStop.month,
  1767. &parseStop.mday,
  1768. &parseStop.hour,
  1769. &parseStop.min,
  1770. &parseStop.sec,
  1771. &parseStop.tz_hour,
  1772. &parseStop.tz_min);
  1773. }
  1774. }
  1775. // Calculate date time difference
  1776. if((parseStart.scanedElement >=6) &&
  1777. (parseStop.scanedElement >=6))
  1778. {
  1779. //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);
  1780. //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);
  1781. tmStart.tm_year = parseStart.year - 1900;
  1782. tmStart.tm_mon = parseStart.month - 1;
  1783. tmStart.tm_mday = parseStart.mday;
  1784. tmStart.tm_hour = parseStart.hour;
  1785. tmStart.tm_min = parseStart.min;
  1786. tmStart.tm_sec = parseStart.sec;
  1787. tmStart.tm_gmtoff = 0;
  1788. tbStart.time = mktime(&tmStart);
  1789. tbStart.timezone = 0;
  1790. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1791. tmStop.tm_year = parseStop.year - 1900;
  1792. tmStop.tm_mon = parseStop.month - 1;
  1793. tmStop.tm_mday = parseStop.mday;
  1794. tmStop.tm_hour = parseStop.hour;
  1795. tmStop.tm_min = parseStop.min;
  1796. tmStop.tm_sec = parseStop.sec;
  1797. tmStop.tm_gmtoff = 0;
  1798. tbStop.time = mktime(&tmStop);
  1799. tbStop.timezone = 0;
  1800. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1801. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1802. //DEBUG_INFO("getStartStop(): %d\n", result);
  1803. }
  1804. else
  1805. {
  1806. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1807. }
  1808. return result;
  1809. }
  1810. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1811. {
  1812. FILE *fp;
  1813. char profileFileName[128];
  1814. char *line = NULL;
  1815. size_t len = 0;
  1816. time_t CurrentTime;
  1817. struct tm *tmComposite;
  1818. struct StructChargingProfile maxProfile;
  1819. struct StructChargingProfile compositeProfile;
  1820. uint8_t limitMax=0;
  1821. int compositePeriodIdx = 0;
  1822. //uint8_t isDurationNull = FALSE;
  1823. CurrentTime = time(NULL);
  1824. tmComposite=localtime(&CurrentTime);
  1825. 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);
  1826. if(isUnitA)
  1827. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1828. else
  1829. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1830. compositeProfile.ChargingSchedule.Duration = durationReq;
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1834. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1835. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1836. }
  1837. compositeProfile.ChargingProfileId = 0;
  1838. compositeProfile.StackLevel = 99 ;
  1839. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1840. maxProfile.ChargingProfileId = -1;
  1841. maxProfile.ChargingSchedule.Duration = -1;
  1842. system("rm -f /tmp/*.json");
  1843. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1844. // Search max profile
  1845. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1846. if((access(profileFileName, F_OK))!=-1)
  1847. {
  1848. fp = fopen(profileFileName, "r");
  1849. while(getline(&line, &len, fp) != -1)
  1850. {
  1851. json_object *obj = NULL;
  1852. obj = json_tokener_parse(line);
  1853. if(is_error(obj))
  1854. {
  1855. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1856. }
  1857. else
  1858. {
  1859. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1860. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1861. )
  1862. {
  1863. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1864. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1865. )
  1866. {
  1867. struct tm tmFrom, tmTo;
  1868. struct timeb tbFrom, tbTo;
  1869. 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) &&
  1870. (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))
  1871. {
  1872. tmFrom.tm_year -= 1900;
  1873. tmFrom.tm_mon -= 1;
  1874. tbFrom.time = mktime(&tmFrom);
  1875. tmTo.tm_year -= 1900;
  1876. tmTo.tm_mon -= 1;
  1877. tbTo.time = mktime(&tmTo);
  1878. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1879. {
  1880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1881. {
  1882. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1883. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1885. }
  1886. if(maxProfile.ChargingProfileId == -1)
  1887. DEBUG_INFO("MaxProfile found.\n");
  1888. else
  1889. DEBUG_INFO("MaxProfile updated.\n");
  1890. // Required item
  1891. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1892. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1893. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1894. if(isUnitA)
  1895. {
  1896. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1897. 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++)
  1898. {
  1899. 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"));
  1900. 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?
  1901. 3:
  1902. 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")));
  1903. 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")));
  1904. }
  1905. }
  1906. else
  1907. {
  1908. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1909. 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++)
  1910. {
  1911. 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"));
  1912. 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?
  1913. 3:
  1914. 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")));
  1915. 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));
  1916. }
  1917. }
  1918. // Optional item
  1919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1920. {
  1921. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1922. }
  1923. else
  1924. {
  1925. sprintf((char*)maxProfile.ValidFrom, " ");
  1926. }
  1927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1928. {
  1929. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1930. }
  1931. else
  1932. {
  1933. sprintf((char*)maxProfile.ValidTo, " ");
  1934. }
  1935. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1936. {
  1937. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1938. }
  1939. else
  1940. {
  1941. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1942. }
  1943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1944. {
  1945. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1946. }
  1947. else
  1948. {
  1949. maxProfile.TransactionId = -1;
  1950. }
  1951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1952. {
  1953. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1954. }
  1955. else
  1956. {
  1957. maxProfile.ChargingSchedule.Duration = 86400;
  1958. //isDurationNull = TRUE;
  1959. }
  1960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1961. {
  1962. 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")));
  1963. }
  1964. else
  1965. {
  1966. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1967. }
  1968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1969. {
  1970. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1971. }
  1972. else
  1973. {
  1974. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1975. }
  1976. }
  1977. }
  1978. }
  1979. else
  1980. {
  1981. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1982. {
  1983. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1984. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1986. }
  1987. if(maxProfile.ChargingProfileId == -1)
  1988. DEBUG_INFO("MaxProfile found.\n");
  1989. else
  1990. DEBUG_INFO("MaxProfile updated.\n");
  1991. // Required item
  1992. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1993. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1994. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1995. if(isUnitA)
  1996. {
  1997. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1998. 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++)
  1999. {
  2000. 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"));
  2001. 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?
  2002. 3:
  2003. 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")));
  2004. 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")));
  2005. }
  2006. }
  2007. else
  2008. {
  2009. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2010. 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++)
  2011. {
  2012. 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"));
  2013. 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?
  2014. 3:
  2015. 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")));
  2016. 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));
  2017. }
  2018. }
  2019. // Optional item
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2021. {
  2022. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)maxProfile.ValidFrom, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2029. {
  2030. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)maxProfile.ValidTo, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2037. {
  2038. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2039. }
  2040. else
  2041. {
  2042. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2043. }
  2044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2045. {
  2046. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2047. }
  2048. else
  2049. {
  2050. maxProfile.TransactionId = -1;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2053. {
  2054. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2055. }
  2056. else
  2057. {
  2058. maxProfile.ChargingSchedule.Duration = 86400;
  2059. //isDurationNull = TRUE;
  2060. }
  2061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2062. {
  2063. 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")));
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2068. }
  2069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2070. {
  2071. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2072. }
  2073. else
  2074. {
  2075. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2076. }
  2077. }
  2078. }
  2079. }
  2080. json_object_put(obj);
  2081. }
  2082. fclose(fp);
  2083. /*
  2084. if(maxProfile.ChargingProfileId !=-1)
  2085. {
  2086. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2087. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2088. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2089. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2090. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2091. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2092. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2093. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2094. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2095. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2096. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2097. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2098. {
  2099. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2100. {
  2101. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2102. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2103. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2104. }
  2105. }
  2106. }
  2107. else
  2108. DEBUG_INFO("MaxProfile not found.\n");
  2109. DEBUG_INFO("------------------------------------\n");*/
  2110. }
  2111. if(maxProfile.ChargingProfileId != -1)
  2112. {
  2113. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2114. {
  2115. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2116. {
  2117. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2118. 0:
  2119. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2120. }
  2121. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2122. {
  2123. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2124. {
  2125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2126. 0:
  2127. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2128. if(idxPeriod > 0)
  2129. {
  2130. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2131. {
  2132. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2139. {
  2140. if(maxProfile.ChargingSchedule.Duration != -1)
  2141. {
  2142. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2143. }
  2144. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2145. {
  2146. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2147. {
  2148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2149. if(idxPeriod > 0)
  2150. {
  2151. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2152. {
  2153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2154. }
  2155. }
  2156. }
  2157. }
  2158. }
  2159. else
  2160. {
  2161. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2162. {
  2163. if(maxProfile.ChargingSchedule.Duration != -1)
  2164. {
  2165. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2166. 0:
  2167. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2168. }
  2169. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2170. {
  2171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2174. 0:
  2175. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2176. if(idxPeriod > 0)
  2177. {
  2178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2179. {
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. else
  2187. {
  2188. if(maxProfile.ChargingSchedule.Duration != -1)
  2189. {
  2190. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2191. 0:
  2192. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2193. }
  2194. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2195. {
  2196. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2197. {
  2198. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2199. 0:
  2200. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2201. if(idxPeriod > 0)
  2202. {
  2203. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2204. {
  2205. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. /*
  2213. DEBUG_INFO("MaxProfile after align.\n");
  2214. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2215. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2216. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2217. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2218. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2219. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2220. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2221. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2222. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2223. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2224. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2225. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2226. {
  2227. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2228. {
  2229. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2230. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2231. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2232. }
  2233. }
  2234. DEBUG_INFO("------------------------------------\n");*/
  2235. }
  2236. // Find each profile period quantity
  2237. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2238. {
  2239. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2240. limitMax = idx+1;
  2241. }
  2242. if(maxProfile.ChargingProfileId != -1)
  2243. {
  2244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2245. {
  2246. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2247. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2248. (maxProfile.ChargingSchedule.Duration > 0))
  2249. {
  2250. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. }
  2261. }
  2262. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2263. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2264. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2265. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2266. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2267. {
  2268. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2269. {
  2270. compositeProfile.ChargingProfileId = 1;
  2271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2274. }
  2275. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2276. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2277. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2278. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2279. }
  2280. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2281. if(line)
  2282. free(line);
  2283. }
  2284. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2285. {
  2286. FILE *fp;
  2287. char profileFileName[128];
  2288. char *line = NULL;
  2289. size_t len = 0;
  2290. time_t CurrentTime;
  2291. struct tm *tmComposite;
  2292. struct StructChargingProfile maxProfile;
  2293. struct StructChargingProfile defaultTxProfile;
  2294. struct StructChargingProfile txProfile;
  2295. struct StructChargingProfile compositeProfile;
  2296. struct StructChargingSchedulePeriod tmpPeriod;
  2297. uint8_t limitMax=0;
  2298. uint8_t limitDef=0;
  2299. uint8_t limitTx=0;
  2300. int compositePeriodIdx = 0;
  2301. CurrentTime = time(NULL);
  2302. tmComposite=localtime(&CurrentTime);
  2303. 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);
  2304. if(isUnitA)
  2305. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2306. else
  2307. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2308. compositeProfile.ChargingSchedule.Duration = durationReq;
  2309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2310. {
  2311. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2312. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2313. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2314. }
  2315. compositeProfile.ChargingProfileId = 0;
  2316. compositeProfile.StackLevel = 99 ;
  2317. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2318. maxProfile.ChargingProfileId = -1;
  2319. defaultTxProfile.ChargingProfileId = -1;
  2320. txProfile.ChargingProfileId = -1;
  2321. maxProfile.ChargingSchedule.Duration = -1;
  2322. defaultTxProfile.ChargingSchedule.Duration = -1;
  2323. txProfile.ChargingSchedule.Duration = -1;
  2324. system("rm -f /tmp/*.json");
  2325. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2326. /*
  2327. * Search valid charging profile
  2328. */
  2329. //DEBUG_INFO("====================================\n");
  2330. // Search tx profile
  2331. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2332. if((access(profileFileName, F_OK))!=-1)
  2333. {
  2334. fp = fopen(profileFileName, "r");
  2335. while(getline(&line, &len, fp) != -1)
  2336. {
  2337. json_object *obj = NULL;
  2338. obj = json_tokener_parse(line);
  2339. if(is_error(obj))
  2340. {
  2341. DEBUG_ERROR("Parse txProfile from file error.\n");
  2342. }
  2343. else
  2344. {
  2345. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2346. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2347. )
  2348. {
  2349. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2350. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2351. )
  2352. {
  2353. struct tm tmFrom, tmTo;
  2354. struct timeb tbFrom, tbTo;
  2355. 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) &&
  2356. (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))
  2357. {
  2358. tmFrom.tm_year -= 1900;
  2359. tmFrom.tm_mon -= 1;
  2360. tbFrom.time = mktime(&tmFrom);
  2361. tmTo.tm_year -= 1900;
  2362. tmTo.tm_mon -= 1;
  2363. tbTo.time = mktime(&tmTo);
  2364. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2365. {
  2366. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2367. {
  2368. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2369. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2370. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2371. }
  2372. if(txProfile.ChargingProfileId == -1)
  2373. DEBUG_INFO("TxProfile found.\n");
  2374. else
  2375. DEBUG_INFO("TxProfile updated.\n");
  2376. // Required item
  2377. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2378. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2379. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2380. if(isUnitA)
  2381. {
  2382. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2383. 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++)
  2384. {
  2385. 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"));
  2386. 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?
  2387. 3:
  2388. 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")));
  2389. 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")));
  2390. }
  2391. }
  2392. else
  2393. {
  2394. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2395. 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++)
  2396. {
  2397. 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"));
  2398. 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?
  2399. 3:
  2400. 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")));
  2401. 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));
  2402. }
  2403. }
  2404. // Optional item
  2405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2406. {
  2407. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2408. }
  2409. else
  2410. {
  2411. sprintf((char*)txProfile.ValidFrom, " ");
  2412. }
  2413. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2414. {
  2415. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2416. }
  2417. else
  2418. {
  2419. sprintf((char*)txProfile.ValidTo, " ");
  2420. }
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2422. {
  2423. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)txProfile.RecurrencyKind, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2430. {
  2431. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2432. }
  2433. else
  2434. {
  2435. txProfile.TransactionId = -1;
  2436. }
  2437. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2438. {
  2439. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2440. }
  2441. else
  2442. {
  2443. txProfile.ChargingSchedule.Duration = 86400;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. 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")));
  2448. }
  2449. else
  2450. {
  2451. 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));
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. txProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. else
  2465. {
  2466. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2467. {
  2468. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2469. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2470. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2471. }
  2472. if(txProfile.ChargingProfileId == -1)
  2473. DEBUG_INFO("TxProfile found.\n");
  2474. else
  2475. DEBUG_INFO("TxProfile updated.\n");
  2476. // Required item
  2477. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2478. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2479. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2480. if(isUnitA)
  2481. {
  2482. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2483. 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++)
  2484. {
  2485. 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"));
  2486. 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?
  2487. 3:
  2488. 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")));
  2489. 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")));
  2490. }
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2495. 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++)
  2496. {
  2497. 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"));
  2498. 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?
  2499. 3:
  2500. 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")));
  2501. 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));
  2502. }
  2503. }
  2504. // Optional item
  2505. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2506. {
  2507. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2508. }
  2509. else
  2510. {
  2511. sprintf((char*)txProfile.ValidFrom, " ");
  2512. }
  2513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2514. {
  2515. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2516. }
  2517. else
  2518. {
  2519. sprintf((char*)txProfile.ValidTo, " ");
  2520. }
  2521. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2522. {
  2523. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2524. }
  2525. else
  2526. {
  2527. sprintf((char*)txProfile.RecurrencyKind, " ");
  2528. }
  2529. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2530. {
  2531. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2532. }
  2533. else
  2534. {
  2535. txProfile.TransactionId = -1;
  2536. }
  2537. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2538. {
  2539. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2540. }
  2541. else
  2542. {
  2543. txProfile.ChargingSchedule.Duration = 86400;
  2544. }
  2545. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2546. {
  2547. 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")));
  2548. }
  2549. else
  2550. {
  2551. 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));
  2552. }
  2553. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2554. {
  2555. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2556. }
  2557. else
  2558. {
  2559. txProfile.ChargingSchedule.MinChargingRate = -1;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. json_object_put(obj);
  2565. }
  2566. fclose(fp);
  2567. /*
  2568. if(txProfile.ChargingProfileId != -1)
  2569. {
  2570. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2571. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2572. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2573. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2574. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2575. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2576. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2577. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2578. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2579. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2580. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2584. {
  2585. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2586. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2587. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2588. }
  2589. }
  2590. }
  2591. else
  2592. DEBUG_INFO("TxProfile not found.\n");*/
  2593. }
  2594. // Search default tx profile
  2595. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2596. if((access(profileFileName, F_OK))==-1)
  2597. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2598. if((access(profileFileName, F_OK))!=-1)
  2599. {
  2600. fp = fopen(profileFileName, "r");
  2601. while(getline(&line, &len, fp) != -1)
  2602. {
  2603. json_object *obj = NULL;
  2604. obj = json_tokener_parse(line);
  2605. if(is_error(obj))
  2606. {
  2607. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2608. }
  2609. else
  2610. {
  2611. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2612. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2613. )
  2614. {
  2615. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2616. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. )
  2618. {
  2619. struct tm tmFrom, tmTo;
  2620. struct timeb tbFrom, tbTo;
  2621. 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) &&
  2622. (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))
  2623. {
  2624. tmFrom.tm_year -= 1900;
  2625. tmFrom.tm_mon -= 1;
  2626. tbFrom.time = mktime(&tmFrom);
  2627. tmTo.tm_year -= 1900;
  2628. tmTo.tm_mon -= 1;
  2629. tbTo.time = mktime(&tmTo);
  2630. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2631. {
  2632. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2633. {
  2634. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2636. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2637. }
  2638. if(defaultTxProfile.ChargingProfileId == -1)
  2639. DEBUG_INFO("TxDefaultProfile found.\n");
  2640. else
  2641. DEBUG_INFO("TxDefaultProfile updated.\n");
  2642. // Required item
  2643. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2644. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2645. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2646. if(isUnitA)
  2647. {
  2648. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2649. 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++)
  2650. {
  2651. 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"));
  2652. 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?
  2653. 3:
  2654. 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")));
  2655. 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")));
  2656. }
  2657. }
  2658. else
  2659. {
  2660. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2661. 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++)
  2662. {
  2663. 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"));
  2664. 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?
  2665. 3:
  2666. 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")));
  2667. 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));
  2668. }
  2669. }
  2670. // Optional item
  2671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2672. {
  2673. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2674. }
  2675. else
  2676. {
  2677. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2678. }
  2679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2680. {
  2681. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2682. }
  2683. else
  2684. {
  2685. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2686. }
  2687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2688. {
  2689. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2690. }
  2691. else
  2692. {
  2693. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2694. }
  2695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2696. {
  2697. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2698. }
  2699. else
  2700. {
  2701. defaultTxProfile.TransactionId = -1;
  2702. }
  2703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2704. {
  2705. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2706. }
  2707. else
  2708. {
  2709. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2710. }
  2711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2712. {
  2713. 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")));
  2714. }
  2715. else
  2716. {
  2717. 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));
  2718. }
  2719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2720. {
  2721. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2722. }
  2723. else
  2724. {
  2725. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. else
  2731. {
  2732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2735. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2736. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2737. }
  2738. if(defaultTxProfile.ChargingProfileId == -1)
  2739. DEBUG_INFO("TxDefaultProfile found.\n");
  2740. else
  2741. DEBUG_INFO("TxDefaultProfile updated.\n");
  2742. // Required item
  2743. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2744. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2745. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2746. if(isUnitA)
  2747. {
  2748. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2749. 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++)
  2750. {
  2751. 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"));
  2752. 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?
  2753. 3:
  2754. 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")));
  2755. 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")));
  2756. }
  2757. }
  2758. else
  2759. {
  2760. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2761. 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++)
  2762. {
  2763. 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"));
  2764. 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?
  2765. 3:
  2766. 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")));
  2767. 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));
  2768. }
  2769. }
  2770. // Optional item
  2771. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2772. {
  2773. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2774. }
  2775. else
  2776. {
  2777. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2778. }
  2779. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2780. {
  2781. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2782. }
  2783. else
  2784. {
  2785. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2786. }
  2787. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2788. {
  2789. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2790. }
  2791. else
  2792. {
  2793. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2794. }
  2795. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2796. {
  2797. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2798. }
  2799. else
  2800. {
  2801. defaultTxProfile.TransactionId = -1;
  2802. }
  2803. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2804. {
  2805. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2806. }
  2807. else
  2808. {
  2809. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2810. }
  2811. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2812. {
  2813. 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")));
  2814. }
  2815. else
  2816. {
  2817. 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));
  2818. }
  2819. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2820. {
  2821. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2822. }
  2823. else
  2824. {
  2825. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2826. }
  2827. }
  2828. }
  2829. }
  2830. json_object_put(obj);
  2831. }
  2832. fclose(fp);
  2833. /*
  2834. if(defaultTxProfile.ChargingProfileId != -1)
  2835. {
  2836. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2837. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2838. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2839. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2840. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2841. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2842. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2843. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2844. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2845. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2846. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2850. {
  2851. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2852. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2853. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2854. }
  2855. }
  2856. }
  2857. else
  2858. DEBUG_INFO("TxDefaultProfile not found.\n");
  2859. DEBUG_INFO("------------------------------------\n");*/
  2860. }
  2861. // Search max profile
  2862. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2863. if((access(profileFileName, F_OK))!=-1)
  2864. {
  2865. fp = fopen(profileFileName, "r");
  2866. while(getline(&line, &len, fp) != -1)
  2867. {
  2868. json_object *obj = NULL;
  2869. obj = json_tokener_parse(line);
  2870. if(is_error(obj))
  2871. {
  2872. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2873. }
  2874. else
  2875. {
  2876. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2877. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2878. )
  2879. {
  2880. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2881. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2882. )
  2883. {
  2884. struct tm tmFrom, tmTo;
  2885. struct timeb tbFrom, tbTo;
  2886. 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) &&
  2887. (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))
  2888. {
  2889. tmFrom.tm_year -= 1900;
  2890. tmFrom.tm_mon -= 1;
  2891. tbFrom.time = mktime(&tmFrom);
  2892. tmTo.tm_year -= 1900;
  2893. tmTo.tm_mon -= 1;
  2894. tbTo.time = mktime(&tmTo);
  2895. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2896. {
  2897. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2898. {
  2899. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2901. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2902. }
  2903. if(maxProfile.ChargingProfileId == -1)
  2904. DEBUG_INFO("MaxProfile found.\n");
  2905. else
  2906. DEBUG_INFO("MaxProfile updated.\n");
  2907. // Required item
  2908. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2909. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2910. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2911. if(isUnitA)
  2912. {
  2913. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2914. 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++)
  2915. {
  2916. 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"));
  2917. 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?
  2918. 3:
  2919. 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")));
  2920. 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")));
  2921. }
  2922. }
  2923. else
  2924. {
  2925. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2926. 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++)
  2927. {
  2928. 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"));
  2929. 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?
  2930. 3:
  2931. 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")));
  2932. 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));
  2933. }
  2934. }
  2935. // Optional item
  2936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2937. {
  2938. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2939. }
  2940. else
  2941. {
  2942. sprintf((char*)maxProfile.ValidFrom, " ");
  2943. }
  2944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2945. {
  2946. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2947. }
  2948. else
  2949. {
  2950. sprintf((char*)maxProfile.ValidTo, " ");
  2951. }
  2952. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2953. {
  2954. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2955. }
  2956. else
  2957. {
  2958. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2959. }
  2960. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2961. {
  2962. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2963. }
  2964. else
  2965. {
  2966. maxProfile.TransactionId = -1;
  2967. }
  2968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2969. {
  2970. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2971. }
  2972. else
  2973. {
  2974. maxProfile.ChargingSchedule.Duration = 86400;
  2975. }
  2976. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2977. {
  2978. 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")));
  2979. }
  2980. else
  2981. {
  2982. 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));
  2983. }
  2984. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2985. {
  2986. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2987. }
  2988. else
  2989. {
  2990. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2991. }
  2992. }
  2993. }
  2994. }
  2995. else
  2996. {
  2997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2998. {
  2999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3002. }
  3003. if(maxProfile.ChargingProfileId == -1)
  3004. DEBUG_INFO("MaxProfile found.\n");
  3005. else
  3006. DEBUG_INFO("MaxProfile updated.\n");
  3007. // Required item
  3008. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3009. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3010. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3011. if(isUnitA)
  3012. {
  3013. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3014. 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++)
  3015. {
  3016. 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"));
  3017. 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?
  3018. 3:
  3019. 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")));
  3020. 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")));
  3021. }
  3022. }
  3023. else
  3024. {
  3025. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3026. 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++)
  3027. {
  3028. 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"));
  3029. 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?
  3030. 3:
  3031. 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")));
  3032. 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));
  3033. }
  3034. }
  3035. // Optional item
  3036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3037. {
  3038. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3039. }
  3040. else
  3041. {
  3042. sprintf((char*)maxProfile.ValidFrom, " ");
  3043. }
  3044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3045. {
  3046. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3047. }
  3048. else
  3049. {
  3050. sprintf((char*)maxProfile.ValidTo, " ");
  3051. }
  3052. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3053. {
  3054. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3055. }
  3056. else
  3057. {
  3058. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3059. }
  3060. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3061. {
  3062. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3063. }
  3064. else
  3065. {
  3066. maxProfile.TransactionId = -1;
  3067. }
  3068. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3069. {
  3070. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3071. }
  3072. else
  3073. {
  3074. maxProfile.ChargingSchedule.Duration = 86400;
  3075. }
  3076. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3077. {
  3078. 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")));
  3079. }
  3080. else
  3081. {
  3082. 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));
  3083. }
  3084. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3085. {
  3086. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3087. }
  3088. else
  3089. {
  3090. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. json_object_put(obj);
  3096. }
  3097. fclose(fp);
  3098. /*
  3099. if(maxProfile.ChargingProfileId !=-1)
  3100. {
  3101. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3102. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3103. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3104. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3105. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3106. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3107. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3108. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3109. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3110. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3111. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3112. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3113. {
  3114. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3115. {
  3116. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3117. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3118. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3119. }
  3120. }
  3121. }
  3122. else
  3123. DEBUG_INFO("MaxProfile not found.\n");
  3124. DEBUG_INFO("------------------------------------\n");*/
  3125. }
  3126. /*
  3127. * Align found profile start schedule & periods
  3128. */
  3129. //DEBUG_INFO("====================================\n");
  3130. /*
  3131. // For local test usage, force modify found profile start schedule info
  3132. 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);
  3133. 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);
  3134. 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);
  3135. */
  3136. if(txProfile.ChargingProfileId != -1)
  3137. {
  3138. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3139. {
  3140. if(txProfile.ChargingSchedule.Duration != -1)
  3141. {
  3142. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3143. 0:
  3144. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3145. }
  3146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3147. {
  3148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3149. {
  3150. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3151. 0:
  3152. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3153. if(idxPeriod > 0)
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3156. {
  3157. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3158. }
  3159. }
  3160. }
  3161. }
  3162. }
  3163. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3164. {
  3165. if(txProfile.ChargingSchedule.Duration != -1)
  3166. {
  3167. 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?
  3168. 0:
  3169. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3170. }
  3171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3172. {
  3173. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3174. {
  3175. 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?
  3176. 0:
  3177. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3178. if(idxPeriod > 0)
  3179. {
  3180. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3181. {
  3182. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3183. }
  3184. }
  3185. }
  3186. }
  3187. }
  3188. else
  3189. {
  3190. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3191. {
  3192. if(txProfile.ChargingSchedule.Duration != -1)
  3193. {
  3194. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3195. 0:
  3196. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3197. }
  3198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3201. {
  3202. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3203. 0:
  3204. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3205. if(idxPeriod > 0)
  3206. {
  3207. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3208. {
  3209. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. else
  3216. {
  3217. if(txProfile.ChargingSchedule.Duration != -1)
  3218. {
  3219. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3220. 0:
  3221. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3222. }
  3223. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3224. {
  3225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3226. {
  3227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3228. 0:
  3229. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3230. if(idxPeriod > 0)
  3231. {
  3232. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3233. {
  3234. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3235. }
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. /*
  3242. DEBUG_INFO("txProfile after align.\n");
  3243. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3244. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3245. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3246. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3247. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3248. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3249. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3250. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3251. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3252. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3253. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3255. {
  3256. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3257. {
  3258. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3259. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3260. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3261. }
  3262. }*/
  3263. }
  3264. if(defaultTxProfile.ChargingProfileId != -1)
  3265. {
  3266. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3267. {
  3268. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3269. {
  3270. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3271. 0:
  3272. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3273. }
  3274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3275. {
  3276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3277. {
  3278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3279. 0:
  3280. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3281. if(idxPeriod > 0)
  3282. {
  3283. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3284. {
  3285. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3286. }
  3287. }
  3288. }
  3289. }
  3290. }
  3291. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3292. {
  3293. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3294. {
  3295. 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?
  3296. 0:
  3297. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3298. }
  3299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3302. {
  3303. 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?
  3304. 0:
  3305. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3306. if(idxPeriod > 0)
  3307. {
  3308. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3309. {
  3310. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. else
  3317. {
  3318. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3319. {
  3320. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3321. {
  3322. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3323. 0:
  3324. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3325. }
  3326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3329. {
  3330. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3331. 0:
  3332. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3333. if(idxPeriod > 0)
  3334. {
  3335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3336. {
  3337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3346. {
  3347. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3348. 0:
  3349. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3350. }
  3351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3352. {
  3353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3354. {
  3355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3356. 0:
  3357. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3358. if(idxPeriod > 0)
  3359. {
  3360. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3361. {
  3362. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. /*
  3370. DEBUG_INFO("defaultTxProfile after align.\n");
  3371. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3372. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3373. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3374. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3375. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3376. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3377. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3378. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3379. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3380. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3381. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3383. {
  3384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3385. {
  3386. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3387. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3388. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3389. }
  3390. }
  3391. DEBUG_INFO("------------------------------------\n");*/
  3392. }
  3393. if(maxProfile.ChargingProfileId != -1)
  3394. {
  3395. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3396. {
  3397. if(maxProfile.ChargingSchedule.Duration != -1)
  3398. {
  3399. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3400. 0:
  3401. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3402. }
  3403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3404. {
  3405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3406. {
  3407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3408. 0:
  3409. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3410. if(idxPeriod > 0)
  3411. {
  3412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3413. {
  3414. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3415. }
  3416. }
  3417. }
  3418. }
  3419. }
  3420. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3421. {
  3422. if(maxProfile.ChargingSchedule.Duration != -1)
  3423. {
  3424. 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?
  3425. 0:
  3426. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3427. }
  3428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3431. {
  3432. 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?
  3433. 0:
  3434. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3435. if(idxPeriod > 0)
  3436. {
  3437. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3438. {
  3439. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3440. }
  3441. }
  3442. }
  3443. }
  3444. }
  3445. else
  3446. {
  3447. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3448. {
  3449. if(maxProfile.ChargingSchedule.Duration != -1)
  3450. {
  3451. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3452. 0:
  3453. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3454. }
  3455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3458. {
  3459. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3460. 0:
  3461. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3462. if(idxPeriod > 0)
  3463. {
  3464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3465. {
  3466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(maxProfile.ChargingSchedule.Duration != -1)
  3475. {
  3476. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3477. 0:
  3478. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3479. }
  3480. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3481. {
  3482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3483. {
  3484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3485. 0:
  3486. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3487. if(idxPeriod > 0)
  3488. {
  3489. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3490. {
  3491. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3492. }
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. /*
  3499. DEBUG_INFO("MaxProfile after align.\n");
  3500. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3501. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3502. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3503. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3504. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3505. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3506. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3507. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3508. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3509. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3510. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3512. {
  3513. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3514. {
  3515. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3516. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3517. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3518. }
  3519. }
  3520. DEBUG_INFO("------------------------------------\n");*/
  3521. }
  3522. /*
  3523. * Merge to conposite schedule
  3524. */
  3525. //DEBUG_INFO("====================================\n");
  3526. // Find each profile period quantity
  3527. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3528. {
  3529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3530. limitMax = idx+1;
  3531. }
  3532. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3533. {
  3534. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3535. limitDef = idx+1;
  3536. }
  3537. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3540. limitTx = idx+1;
  3541. }
  3542. // TxProfile found, composite schedule based on it
  3543. if(txProfile.ChargingProfileId != -1)
  3544. {
  3545. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3546. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3547. {
  3548. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3549. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3550. (txProfile.ChargingSchedule.Duration > 0))
  3551. {
  3552. if(maxProfile.ChargingProfileId != -1)
  3553. {
  3554. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3555. {
  3556. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3557. {
  3558. if((maxProfile.ChargingSchedule.Duration > 0))
  3559. {
  3560. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3561. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3562. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3563. }
  3564. else
  3565. {
  3566. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3567. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3568. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3569. }
  3570. }
  3571. if(idxMaxPeriod == (limitMax-1))
  3572. {
  3573. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3574. {
  3575. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3576. {
  3577. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3578. compositePeriodIdx++;
  3579. }
  3580. else
  3581. {
  3582. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3583. }
  3584. }
  3585. }
  3586. }
  3587. }
  3588. else
  3589. {
  3590. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3591. {
  3592. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3593. compositePeriodIdx++;
  3594. }
  3595. else
  3596. {
  3597. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3598. }
  3599. }
  3600. }
  3601. if(idxTxPeriod == (limitTx-1))
  3602. {
  3603. if(defaultTxProfile.ChargingProfileId != -1)
  3604. {
  3605. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3606. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3607. {
  3608. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3609. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3610. (defaultTxProfile.ChargingSchedule.Duration>0))
  3611. {
  3612. if(maxProfile.ChargingProfileId != -1)
  3613. {
  3614. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3615. {
  3616. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3617. {
  3618. if((maxProfile.ChargingSchedule.Duration > 0))
  3619. {
  3620. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3621. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3622. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3623. }
  3624. else
  3625. {
  3626. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3627. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3628. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3629. }
  3630. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3631. {
  3632. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3633. {
  3634. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3635. compositePeriodIdx++;
  3636. }
  3637. else
  3638. {
  3639. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3640. }
  3641. }
  3642. // Delete duplicate period
  3643. if(compositePeriodIdx > 1)
  3644. {
  3645. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3646. {
  3647. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3648. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3649. compositePeriodIdx -= 1;
  3650. }
  3651. }
  3652. }
  3653. else
  3654. {
  3655. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3656. {
  3657. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3658. compositePeriodIdx++;
  3659. }
  3660. else
  3661. {
  3662. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3663. }
  3664. break;
  3665. }
  3666. }
  3667. }
  3668. else
  3669. {
  3670. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3671. {
  3672. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3673. compositePeriodIdx++;
  3674. }
  3675. else
  3676. {
  3677. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3678. }
  3679. }
  3680. }
  3681. }
  3682. }
  3683. }
  3684. }
  3685. }
  3686. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3687. else if(defaultTxProfile.ChargingProfileId != -1)
  3688. {
  3689. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3690. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3691. {
  3692. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3693. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3694. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3695. {
  3696. if(maxProfile.ChargingProfileId != -1)
  3697. {
  3698. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3699. {
  3700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3701. {
  3702. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3703. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3704. if((maxProfile.ChargingSchedule.Duration > 0))
  3705. {
  3706. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3707. }
  3708. else
  3709. {
  3710. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3711. }
  3712. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3713. {
  3714. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3715. {
  3716. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3717. compositePeriodIdx++;
  3718. }
  3719. else
  3720. {
  3721. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3722. }
  3723. }
  3724. // Delete duplicate period
  3725. if(compositePeriodIdx > 1)
  3726. {
  3727. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3728. {
  3729. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3730. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3731. compositePeriodIdx -= 1;
  3732. }
  3733. }
  3734. }
  3735. else
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3738. {
  3739. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3740. compositePeriodIdx++;
  3741. }
  3742. else
  3743. {
  3744. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3745. }
  3746. break;
  3747. }
  3748. }
  3749. }
  3750. else
  3751. {
  3752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3753. {
  3754. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3755. compositePeriodIdx++;
  3756. }
  3757. else
  3758. {
  3759. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3760. }
  3761. }
  3762. }
  3763. }
  3764. }
  3765. // Fill other period by MaxProfile
  3766. if(maxProfile.ChargingProfileId != -1)
  3767. {
  3768. if(compositePeriodIdx==0)
  3769. {
  3770. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3771. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3772. {
  3773. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3774. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3775. (maxProfile.ChargingSchedule.Duration > 0))
  3776. {
  3777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3778. {
  3779. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3780. compositePeriodIdx++;
  3781. }
  3782. else
  3783. {
  3784. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3785. }
  3786. }
  3787. }
  3788. }
  3789. else
  3790. {
  3791. int lastCompositePeriodIdx = compositePeriodIdx;
  3792. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3793. {
  3794. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3795. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3796. (maxProfile.ChargingSchedule.Duration > 0))
  3797. {
  3798. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3799. {
  3800. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3801. {
  3802. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3803. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3804. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3805. }
  3806. else
  3807. {
  3808. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3809. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3810. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3811. }
  3812. }
  3813. if(tmpPeriod.Limit != -1)
  3814. {
  3815. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3816. {
  3817. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3818. {
  3819. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3820. compositePeriodIdx++;
  3821. }
  3822. else
  3823. {
  3824. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3825. }
  3826. }
  3827. // Delete duplicate period
  3828. if(compositePeriodIdx > 1)
  3829. {
  3830. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3831. {
  3832. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3833. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3834. compositePeriodIdx -= 1;
  3835. }
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. compositeProfile.ChargingSchedule.Duration = durationReq;
  3843. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3844. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3845. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3846. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3848. {
  3849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3850. {
  3851. compositeProfile.ChargingProfileId = 1;
  3852. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3853. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3854. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3855. }
  3856. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3857. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3858. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3859. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3860. }
  3861. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3862. if(line)
  3863. free(line);
  3864. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3865. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3866. }
  3867. //==========================================
  3868. // Init all share memory
  3869. //==========================================
  3870. int InitShareMemory()
  3871. {
  3872. int result = PASS;
  3873. int MeterSMId;
  3874. //creat ShmSysConfigAndInfo
  3875. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3876. {
  3877. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3878. result = FAIL;
  3879. }
  3880. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3881. {
  3882. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3883. result = FAIL;
  3884. }
  3885. else
  3886. {}
  3887. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3888. {
  3889. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3890. result = FAIL;
  3891. }
  3892. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3893. {
  3894. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3895. result = FAIL;
  3896. }
  3897. else
  3898. {}
  3899. //creat ShmPsuData
  3900. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3901. {
  3902. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3903. result = FAIL;
  3904. }
  3905. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3906. {
  3907. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3908. result = FAIL;
  3909. }
  3910. else
  3911. {}
  3912. //creat ShmOCPP16Data
  3913. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3914. {
  3915. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3916. result = FAIL;
  3917. }
  3918. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3919. {
  3920. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3921. result = FAIL;
  3922. }
  3923. else
  3924. {}
  3925. /****************************** For Initial Settings************************************************/
  3926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3928. // allocate Configuration memory address
  3929. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3930. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3931. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3932. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3933. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3934. //offline MeterValue Interval
  3935. TempMeterValueInterval = 0;
  3936. return result;
  3937. }
  3938. int ProcessShareMemory()
  3939. {
  3940. int result = PASS;
  3941. if(InitShareMemory() == FAIL)
  3942. {
  3943. DEBUG_ERROR("InitShareMemory NG\n");
  3944. if(ShmStatusCodeData!=NULL)
  3945. {
  3946. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3947. }
  3948. result = FAIL;
  3949. }
  3950. // Model name parsing
  3951. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3952. {
  3953. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3954. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3955. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3956. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3957. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3958. ) // 'D' means DC
  3959. {
  3960. // DO series
  3961. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3962. {
  3963. gunTotalNumber += 1;
  3964. gunType[gun_index] = GUN_TYPE_DO;
  3965. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3966. {
  3967. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3968. {
  3969. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3970. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3971. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3972. }
  3973. }
  3974. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3975. {
  3976. case Gun_Type_Chademo:
  3977. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3978. break;
  3979. case Gun_Type_CCS_2:
  3980. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3981. break;
  3982. case Gun_Type_GB:
  3983. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3984. break;
  3985. case Gun_Type_AC:
  3986. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3987. break;
  3988. default:
  3989. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3990. break;
  3991. }
  3992. }
  3993. }
  3994. else
  3995. {
  3996. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3997. {
  3998. gunTotalNumber += 1;
  3999. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4000. {
  4001. case Gun_Type_Chademo:
  4002. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4003. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4004. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4007. {
  4008. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4009. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4010. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4011. }
  4012. }
  4013. break;
  4014. case Gun_Type_CCS_2:
  4015. gunType[gun_index] = GUN_TYPE_CCS;
  4016. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4017. for (int index = 0; index < CCS_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4020. {
  4021. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4022. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4023. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4024. }
  4025. }
  4026. break;
  4027. case Gun_Type_GB:
  4028. gunType[gun_index] = GUN_TYPE_GBT;
  4029. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4030. for (int index = 0; index < GB_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4033. {
  4034. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4035. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4036. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4037. }
  4038. }
  4039. break;
  4040. case Gun_Type_AC:
  4041. gunType[gun_index] = GUN_TYPE_AC;
  4042. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4043. for (int index = 0; index < AC_QUANTITY; index++)
  4044. {
  4045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4046. {
  4047. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4048. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4049. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4050. }
  4051. }
  4052. break;
  4053. default:
  4054. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4055. break;
  4056. }
  4057. }
  4058. }
  4059. }
  4060. else
  4061. {
  4062. DEBUG_ERROR("Model name parsing fail.\n");
  4063. result = FAIL;
  4064. }
  4065. if(result != PASS)sleep(5);
  4066. return result;
  4067. }
  4068. void checkRemoteStart(uint8_t connectorIdInt)
  4069. {
  4070. uint8_t tempIndex;
  4071. int result = PASS;
  4072. char cmdBuf[512];
  4073. //check Transaction active
  4074. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4075. {
  4076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4077. {
  4078. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4079. }
  4080. else
  4081. {
  4082. tempIndex = connectorIdInt -1;
  4083. }
  4084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4085. {
  4086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4087. {
  4088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4090. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4091. {
  4092. //Reserved
  4093. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4094. }
  4095. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4096. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4097. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4098. {
  4099. //Reserved
  4100. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4101. result = FAIL;
  4102. goto end;
  4103. }
  4104. else
  4105. {
  4106. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4107. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4108. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4109. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4110. {
  4111. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4112. result = FAIL;
  4113. goto end;
  4114. }
  4115. }//END FOR ELSE
  4116. }
  4117. }// END FOR CHAdeMO_QUANTITY
  4118. }
  4119. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4120. {
  4121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4122. {
  4123. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4124. }
  4125. else
  4126. {
  4127. tempIndex = connectorIdInt -1;
  4128. }
  4129. for (int index = 0; index < CCS_QUANTITY; index++)
  4130. {
  4131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4132. {
  4133. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4134. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4135. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4136. {
  4137. //Reserved
  4138. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4139. }
  4140. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4141. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4142. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4143. {
  4144. //Reserved
  4145. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4146. result = FAIL;
  4147. goto end;
  4148. }
  4149. else
  4150. {
  4151. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4152. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4153. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4155. {
  4156. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4157. result = FAIL;
  4158. goto end;
  4159. }
  4160. }// END FOR ELSE
  4161. }
  4162. }// END FOR CCS_QUANTITY
  4163. }
  4164. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4165. {
  4166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4167. {
  4168. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4169. }
  4170. else
  4171. {
  4172. tempIndex = connectorIdInt -1;
  4173. }
  4174. for (int index = 0; index < GB_QUANTITY; index++)
  4175. {
  4176. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4177. {
  4178. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4179. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4180. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4181. {
  4182. //Reserved
  4183. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4184. }
  4185. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4187. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4188. {
  4189. //Reserved
  4190. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4191. result = FAIL;
  4192. goto end;
  4193. }
  4194. else
  4195. {
  4196. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4197. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4200. {
  4201. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4202. result = FAIL;
  4203. goto end;
  4204. }
  4205. }// END FOR ELSE
  4206. }
  4207. } // END FOR GB_QUANTITY
  4208. }
  4209. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4210. {
  4211. tempIndex = connectorIdInt -1;
  4212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4215. {
  4216. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4217. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4219. {
  4220. //Reserved
  4221. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4222. }
  4223. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4224. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4225. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4226. {
  4227. //Reserved
  4228. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4229. result = FAIL;
  4230. goto end;
  4231. }
  4232. else
  4233. {
  4234. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4235. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4237. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4238. {
  4239. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4240. result = FAIL;
  4241. goto end;
  4242. }
  4243. }// END FOR ELSE
  4244. }
  4245. } // END FOR GB_QUANTITY
  4246. }
  4247. else
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4250. {
  4251. tempIndex = 2;
  4252. }
  4253. else
  4254. {
  4255. tempIndex = connectorIdInt -1;
  4256. }
  4257. for (int index = 0; index < AC_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4260. {
  4261. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4263. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4264. {
  4265. //Reserved
  4266. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4267. }
  4268. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4269. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4270. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4271. {
  4272. //Reserved
  4273. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4274. result = FAIL;
  4275. goto end;
  4276. }
  4277. else
  4278. {
  4279. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4280. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4283. {
  4284. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4285. result = FAIL;
  4286. goto end;
  4287. }
  4288. }//END FOR ELSE
  4289. }
  4290. }// END FOR AC_QUANTITY
  4291. }
  4292. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4293. {
  4294. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4295. {
  4296. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4297. {
  4298. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4299. system(cmdBuf);
  4300. }
  4301. }
  4302. else
  4303. {
  4304. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4305. result = FAIL;
  4306. }
  4307. }
  4308. end:
  4309. if(result == PASS)
  4310. {
  4311. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4312. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4313. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4314. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4315. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4316. }
  4317. }
  4318. void CheckSystemValue(void)
  4319. {
  4320. char filenmae[100]={0};
  4321. char str[100]={0};
  4322. int tempIndex = 0;
  4323. //===============================
  4324. // send Heartbeat
  4325. //===============================
  4326. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4327. {
  4328. //parameter for test
  4329. sendHeartbeatRequest(0);
  4330. //===========================
  4331. // Reset Waiting Time
  4332. //===========================
  4333. HeartBeatWithNOResponse += 1;
  4334. }
  4335. //===============================
  4336. // Credit deduct report
  4337. //===============================
  4338. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4339. {
  4340. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4341. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4342. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4343. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4344. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4345. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4346. }
  4347. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4348. {
  4349. OCPP_query_deduct_info();
  4350. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4351. }
  4352. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4353. {
  4354. // ClockAlign MeterValue
  4355. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4356. {
  4357. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4368. {
  4369. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4370. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4371. {
  4372. reqClockAlignMeter[gun_index] = 1;
  4373. }
  4374. }// End for CHAdeMO
  4375. }
  4376. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4379. {
  4380. tempIndex = ((gun_index==2) ? 1: 0);
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < CCS_QUANTITY; index++)
  4387. {
  4388. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4389. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4390. {
  4391. reqClockAlignMeter[gun_index] = 1;
  4392. }
  4393. } // End for CCS
  4394. }
  4395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4398. {
  4399. tempIndex = ((gun_index==2) ? 1: 0);
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < GB_QUANTITY; index++)
  4406. {
  4407. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4408. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4409. {
  4410. reqClockAlignMeter[gun_index] = 1;
  4411. }
  4412. }// End for GB
  4413. }
  4414. else if(gunType[gun_index] == GUN_TYPE_DO)
  4415. {
  4416. tempIndex = gun_index;
  4417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4418. {
  4419. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4420. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4421. {
  4422. reqClockAlignMeter[gun_index] = 1;
  4423. }
  4424. }
  4425. }
  4426. else
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4429. {
  4430. tempIndex = 2;
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < AC_QUANTITY; index++)
  4437. {
  4438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4439. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4440. {
  4441. reqClockAlignMeter[gun_index] = 1;
  4442. }
  4443. }//End for AC
  4444. }
  4445. }
  4446. }
  4447. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4448. {
  4449. //==========================================
  4450. // Check remote start without connector id
  4451. //==========================================
  4452. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4453. {
  4454. int connectorIdInt = -1;
  4455. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4456. {
  4457. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4458. {
  4459. connectorIdInt = (gun_index+1);
  4460. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4461. checkRemoteStart(connectorIdInt);
  4462. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4463. break;
  4464. }
  4465. }
  4466. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4467. {
  4468. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4469. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4470. }
  4471. }
  4472. //==========================================
  4473. // csu trigger DataTransferReq
  4474. //==========================================
  4475. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4476. {
  4477. sendDataTransferRequest(gun_index);
  4478. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4479. }
  4480. //==========================================
  4481. // CSU Trigger Authorize Request
  4482. //==========================================
  4483. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4484. {
  4485. sendAuthorizeRequest(0);
  4486. authorizeRetryTimes = authorizeRetryTimes + 1;
  4487. if(authorizeRetryTimes < 3)
  4488. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4489. }
  4490. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4491. {
  4492. authorizeRetryTimes = 0;
  4493. SetOcppConnStatus(FALSE);
  4494. server_sign = FALSE;
  4495. }
  4496. 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))
  4497. {
  4498. sendAuthorizeRequest(0);
  4499. }
  4500. //==========================================
  4501. // Charger start transaction
  4502. //==========================================
  4503. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4504. {
  4505. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4506. sendStartTransactionRequest(gun_index);
  4507. refreshStartTimer(&clientTime.StartTransaction);
  4508. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4509. storeTempStopTransaction(gun_index);
  4510. }
  4511. //==========================================
  4512. // Charger stop transaction
  4513. //==========================================
  4514. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4515. {
  4516. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4517. sendStopTransactionRequest(gun_index);
  4518. OCPP_updatePeriodEnergy(gun_index);
  4519. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4520. refreshStartTimer(&clientTime.StopTransaction);
  4521. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4522. }
  4523. //==========================================
  4524. // Charger status report
  4525. //==========================================
  4526. //--- Check Mode Change ---//
  4527. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4528. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4531. {
  4532. tempIndex = ((gun_index==2) ? 1: 0);
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4541. {
  4542. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4543. {
  4544. // Sent unplug message for California pricing logic
  4545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4546. {
  4547. uint8_t ts[36];
  4548. getNowDatetime(ts);
  4549. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4550. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4551. if(strcmp((char*)dmsVersion, "2.0")==0)
  4552. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4553. else
  4554. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4555. sendUnplugByDataTransferRequest(gun_index);
  4556. interLock.isSentUnplug[gun_index] = 1;
  4557. }
  4558. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4559. {
  4560. interLock.isSentUnplug[gun_index] = 0;
  4561. }
  4562. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4563. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4564. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4565. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4566. {
  4567. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4568. if((access(filenmae,F_OK))!=-1)
  4569. {
  4570. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4571. sprintf(str,"rm -f %s",filenmae);
  4572. system(str);
  4573. }
  4574. }
  4575. }
  4576. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4577. #if 1 // for TempStopTransaction
  4578. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4579. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4580. {
  4581. checkTempStopTransaction(gun_index);
  4582. }
  4583. #endif
  4584. }
  4585. }
  4586. }
  4587. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4590. {
  4591. tempIndex = ((gun_index==2) ? 1: 0);
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < CCS_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4600. {
  4601. 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]*/ )
  4602. {
  4603. // Sent unplug message for California pricing logic
  4604. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4605. {
  4606. uint8_t ts[36];
  4607. getNowDatetime(ts);
  4608. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4609. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4610. if(strcmp((char*)dmsVersion, "2.0")==0)
  4611. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4612. else
  4613. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4614. sendUnplugByDataTransferRequest(gun_index);
  4615. interLock.isSentUnplug[gun_index] = 1;
  4616. }
  4617. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4618. {
  4619. interLock.isSentUnplug[gun_index] = 0;
  4620. }
  4621. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4622. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4623. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4624. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4625. {
  4626. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4627. if((access(filenmae,F_OK))!=-1)
  4628. {
  4629. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4630. sprintf(str,"rm -f %s",filenmae);
  4631. system(str);
  4632. }
  4633. }
  4634. }
  4635. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4636. #if 1 // for TempStopTransaction
  4637. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4638. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4639. {
  4640. checkTempStopTransaction(gun_index);
  4641. }
  4642. #endif
  4643. }
  4644. }
  4645. }
  4646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4647. {
  4648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4649. {
  4650. tempIndex = ((gun_index==2) ? 1: 0);
  4651. }
  4652. else
  4653. {
  4654. tempIndex = gun_index;
  4655. }
  4656. for (int index = 0; index < GB_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4659. {
  4660. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4661. {
  4662. // Sent unplug message for California pricing logic
  4663. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4664. {
  4665. uint8_t ts[36];
  4666. getNowDatetime(ts);
  4667. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4668. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4669. if(strcmp((char*)dmsVersion, "2.0")==0)
  4670. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4671. else
  4672. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4673. sendUnplugByDataTransferRequest(gun_index);
  4674. interLock.isSentUnplug[gun_index] = 1;
  4675. }
  4676. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4677. {
  4678. interLock.isSentUnplug[gun_index] = 0;
  4679. }
  4680. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4681. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4682. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4684. {
  4685. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4686. if((access(filenmae,F_OK))!=-1)
  4687. {
  4688. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4689. sprintf(str,"rm -f %s",filenmae);
  4690. system(str);
  4691. }
  4692. }
  4693. }
  4694. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4695. #if 1 // for TempStopTransaction
  4696. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4697. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4698. {
  4699. checkTempStopTransaction(gun_index);
  4700. }
  4701. #endif
  4702. }
  4703. }
  4704. }
  4705. else if(gunType[gun_index] == GUN_TYPE_DO)
  4706. {
  4707. tempIndex = gun_index;
  4708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4709. {
  4710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4711. {
  4712. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4713. {
  4714. // Sent unplug message for California pricing logic
  4715. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4716. {
  4717. uint8_t ts[36];
  4718. getNowDatetime(ts);
  4719. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4720. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4721. if(strcmp((char*)dmsVersion, "2.0")==0)
  4722. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4723. else
  4724. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4725. sendUnplugByDataTransferRequest(gun_index);
  4726. interLock.isSentUnplug[gun_index] = 1;
  4727. }
  4728. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4729. {
  4730. interLock.isSentUnplug[gun_index] = 0;
  4731. }
  4732. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4733. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4734. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4735. 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
  4736. {
  4737. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4738. if((access(filenmae,F_OK))!=-1)
  4739. {
  4740. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4741. sprintf(str,"rm -f %s",filenmae);
  4742. system(str);
  4743. }
  4744. }
  4745. }
  4746. 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);
  4747. #if 1 // for TempStopTransaction
  4748. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4749. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4750. {
  4751. checkTempStopTransaction(gun_index);
  4752. }
  4753. #endif
  4754. }
  4755. }
  4756. }
  4757. else
  4758. {
  4759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4760. {
  4761. tempIndex = 2;
  4762. }
  4763. else
  4764. {
  4765. tempIndex = gun_index;
  4766. }
  4767. for (int index = 0; index < AC_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4770. {
  4771. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4772. {
  4773. // Sent unplug message for California pricing logic
  4774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4775. {
  4776. uint8_t ts[36];
  4777. getNowDatetime(ts);
  4778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4780. if(strcmp((char*)dmsVersion, "2.0")==0)
  4781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4782. else
  4783. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4784. sendUnplugByDataTransferRequest(gun_index);
  4785. interLock.isSentUnplug[gun_index] = 1;
  4786. }
  4787. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4788. {
  4789. interLock.isSentUnplug[gun_index] = 0;
  4790. }
  4791. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4792. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4793. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4794. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4795. {
  4796. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4797. if((access(filenmae,F_OK))!=-1)
  4798. {
  4799. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4800. sprintf(str,"rm -f %s",filenmae);
  4801. system(str);
  4802. }
  4803. }
  4804. }
  4805. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4806. #if 1 // for TempStopTransaction
  4807. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4808. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4809. {
  4810. checkTempStopTransaction(gun_index);
  4811. }
  4812. #endif
  4813. }
  4814. }// END
  4815. }
  4816. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4817. (
  4818. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4819. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4820. )
  4821. )
  4822. {
  4823. sendStatusNotificationRequest(gun_index);
  4824. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4825. }
  4826. //==============================================
  4827. // TCCI reader status report
  4828. //==============================================
  4829. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4830. {
  4831. reportReaderStatus(gun_index);
  4832. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4833. }
  4834. //==============================================
  4835. // CSU Trigger Smart Charging Profile
  4836. //==============================================
  4837. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4838. {
  4839. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4840. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4841. }
  4842. //==============================================
  4843. // Meter report
  4844. //==============================================
  4845. // Trigger MeterValue
  4846. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4847. {
  4848. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4849. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4850. }
  4851. // Clock-aligned Meter value
  4852. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4853. {
  4854. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4855. reqClockAlignMeter[gun_index] = 0;
  4856. }
  4857. // Sample period MeterValue
  4858. 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))))
  4859. {
  4860. //check Transaction active
  4861. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4864. {
  4865. tempIndex = ((gun_index==2) ? 1: 0);
  4866. }
  4867. else
  4868. {
  4869. tempIndex = gun_index;
  4870. }
  4871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4872. {
  4873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4874. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4875. {
  4876. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4877. {
  4878. reqSampleMeter[gun_index] = 1;
  4879. }
  4880. }
  4881. }// End for CHAdeMO
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < CCS_QUANTITY; index++)
  4894. {
  4895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4899. {
  4900. reqSampleMeter[gun_index] = 1;
  4901. }
  4902. }
  4903. } // End for CCS
  4904. }
  4905. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4906. {
  4907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4908. {
  4909. tempIndex = ((gun_index==2) ? 1: 0);
  4910. }
  4911. else
  4912. {
  4913. tempIndex = gun_index;
  4914. }
  4915. for (int index = 0; index < GB_QUANTITY; index++)
  4916. {
  4917. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4918. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4919. {
  4920. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4921. {
  4922. reqSampleMeter[gun_index] = 1;
  4923. }
  4924. }
  4925. }// End for GB
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_DO)
  4928. {
  4929. tempIndex = gun_index;
  4930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4931. {
  4932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4933. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4936. {
  4937. reqSampleMeter[gun_index] = 1;
  4938. }
  4939. }
  4940. }
  4941. }
  4942. else
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4945. {
  4946. tempIndex = 2;
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < AC_QUANTITY; index++)
  4953. {
  4954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4955. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4956. {
  4957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4958. {
  4959. reqSampleMeter[gun_index] = 1;
  4960. }
  4961. }
  4962. }//End for AC
  4963. }
  4964. if(reqSampleMeter[gun_index] == 1)
  4965. {
  4966. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4967. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4968. storeTempStopTransaction(gun_index);
  4969. reqSampleMeter[gun_index] = 0;
  4970. }
  4971. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4972. }
  4973. //==============================================
  4974. // Check Connector reserved
  4975. //==============================================
  4976. //===============================
  4977. // Check if Reserve is expired
  4978. //===============================
  4979. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4980. {
  4981. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4982. {
  4983. DEBUG_INFO("reserve expired.\n");
  4984. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4985. }
  4986. }//END OF Check if Reserve is expired
  4987. //==========================================
  4988. // csu trigger FirmwareStatusNotificationReq
  4989. //==========================================
  4990. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4991. {
  4992. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4993. }
  4994. //==========================================
  4995. // csu trigger DiagnosticsStatusNotificationReq
  4996. //==========================================
  4997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4998. {
  4999. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5000. }
  5001. //==========================================
  5002. // csu trigger CancelReservationConf
  5003. //==========================================
  5004. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5005. {
  5006. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5007. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5008. }
  5009. //==========================================
  5010. // csu trigger ChangeAvailabilityConf
  5011. //==========================================
  5012. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5013. {
  5014. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5015. }
  5016. //==========================================
  5017. // csu trigger UnlockConnectorConf
  5018. //==========================================
  5019. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5020. {
  5021. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5022. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5023. }
  5024. //==========================================
  5025. // csu trigger ReserveNowConf
  5026. //==========================================
  5027. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5028. {
  5029. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5030. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5031. }
  5032. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5033. {
  5034. sendSignCertificateRequest();
  5035. }
  5036. }
  5037. }
  5038. //==========================================
  5039. // send request routine
  5040. //==========================================
  5041. int sendAuthorizeRequest(int gun_index)
  5042. {
  5043. mtrace();
  5044. int result = FAIL;
  5045. char message[100]={0};
  5046. char guid[37];
  5047. char tempdata[65]={0};
  5048. DEBUG_INFO("sendAuthorizeRequest...\n");
  5049. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5050. //Local Authorize
  5051. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5052. {
  5053. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5054. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5055. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5056. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5057. result = PASS;
  5058. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5059. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5060. authorizeRetryTimes = 0;
  5061. return result;
  5062. }
  5063. 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))||
  5064. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5065. {
  5066. // Query from cache
  5067. DEBUG_INFO("Authorize from cache.\n");
  5068. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5069. // Query from list
  5070. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5071. {
  5072. DEBUG_INFO("Authorize from list.\n");
  5073. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5074. }
  5075. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5076. {
  5077. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5078. {
  5079. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5080. }
  5081. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5082. {
  5083. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5084. }
  5085. if(!GetOcppConnStatus())
  5086. {
  5087. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5088. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5089. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5090. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5091. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5092. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5093. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5094. authorizeRetryTimes = 0;
  5095. return result;
  5096. }
  5097. }
  5098. else
  5099. {
  5100. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5101. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5102. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5103. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5104. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5105. else
  5106. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5107. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5108. result = PASS;
  5109. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5110. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5111. authorizeRetryTimes = 0;
  5112. return result;
  5113. }
  5114. }
  5115. //initialize struct Authorize
  5116. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5117. //get data from shared memory
  5118. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5119. random_uuid(guid);
  5120. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5121. LWS_Send(message);
  5122. sprintf(tempdata, "Authorize,%d", gun_index);
  5123. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5124. {
  5125. result = PASS;
  5126. DEBUG_INFO("Authorize mapItem pass\n");
  5127. }
  5128. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5129. return result;
  5130. }
  5131. int sendBootNotificationRequest(void)
  5132. {
  5133. mtrace();
  5134. int result = FAIL;
  5135. char message[500]={0}, payload[700]={0};
  5136. char guid[37]={0};
  5137. char tempdata[65]={0};
  5138. // Fill BootNotification fields
  5139. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5140. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5141. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5142. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5143. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5144. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5145. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5146. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5147. ShmOCPP16Data->ChargeBoxId
  5148. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5149. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5150. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5151. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5152. ,ShmOCPP16Data->BootNotification.CpIccid
  5153. ,ShmOCPP16Data->BootNotification.CpImsi);
  5154. random_uuid(guid);
  5155. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5156. LWS_Send(message);
  5157. sprintf(tempdata, "BootNotification,0");
  5158. 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*/)
  5159. {
  5160. result = PASS;
  5161. }
  5162. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5163. strcpy(queuedata,message);
  5164. return result;
  5165. }
  5166. int sendDataTransferRequest(int gun_index)
  5167. {
  5168. mtrace();
  5169. char message[1000]={0};
  5170. char guid[37]={0};
  5171. char tempdata[65]={0};
  5172. int result = FAIL;
  5173. random_uuid(guid);
  5174. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5175. MESSAGE_TYPE_CALL,
  5176. guid,
  5177. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5178. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5179. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5180. LWS_Send(message);
  5181. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5182. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5183. {
  5184. result = PASS;
  5185. DEBUG_INFO("DataTransfer mapItem pass\n");
  5186. }
  5187. return result;
  5188. }
  5189. int sendUnplugByDataTransferRequest(int gun_index)
  5190. {
  5191. mtrace();
  5192. char message[1000]={0};
  5193. char guid[37]={0};
  5194. char tempdata[65]={0};
  5195. int result = FAIL;
  5196. random_uuid(guid);
  5197. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5198. (gun_index+1),
  5199. MESSAGE_TYPE_CALL,
  5200. guid,
  5201. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5202. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5203. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5204. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5206. {
  5207. result = PASS;
  5208. DEBUG_INFO("DataTransfer mapItem pass\n");
  5209. }
  5210. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5211. return result;
  5212. }
  5213. int sendDiagnosticsStatusNotificationRequest(char *status)
  5214. {
  5215. mtrace();
  5216. int result = FAIL;
  5217. char message[110]={0};
  5218. char guid[37]={0};
  5219. char tempdata[65]={0};
  5220. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5221. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5222. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5223. random_uuid(guid);
  5224. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5225. LWS_SendNow(message);
  5226. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5227. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5228. {
  5229. result = PASS;
  5230. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5231. }
  5232. //#ifdef SystemLogMessage
  5233. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5234. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5235. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5236. //#endif
  5237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5238. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5239. //record status
  5240. if(strcmp(status,"Idle")==0)
  5241. {
  5242. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5243. }
  5244. else if(strcmp(status,"Uploaded")==0)
  5245. {
  5246. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5247. }
  5248. else if(strcmp(status,"UploadFailed")==0)
  5249. {
  5250. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5251. }
  5252. else if(strcmp(status,"Uploading")==0)
  5253. {
  5254. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5255. }
  5256. return result;
  5257. }
  5258. int sendFirmwareStatusNotificationRequest(char *status)
  5259. {
  5260. mtrace();
  5261. int result = FAIL;
  5262. char message[110]={0};
  5263. char guid[37]={0};
  5264. char tempdata[65]={0};
  5265. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5266. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5267. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5268. random_uuid(guid);
  5269. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5270. LWS_SendNow(message);
  5271. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5272. 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*/)
  5273. {
  5274. result = PASS;
  5275. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5276. }
  5277. //#ifdef SystemLogMessage
  5278. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5279. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5280. //#endif
  5281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5282. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5283. //record status
  5284. if(strcmp(status,"Downloaded")==0)
  5285. {
  5286. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5287. }
  5288. else if(strcmp(status,"DownloadFailed")==0)
  5289. {
  5290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5291. }
  5292. else if(strcmp(status,"Downloading")==0)
  5293. {
  5294. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5295. }
  5296. else if(strcmp(status,"Idle")==0)
  5297. {
  5298. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5299. }
  5300. else if(strcmp(status,"InstallationFailed")==0)
  5301. {
  5302. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5303. }
  5304. else if(strcmp(status,"Installing")==0)
  5305. {
  5306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5307. }
  5308. else if(strcmp(status,"Installed")==0)
  5309. {
  5310. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5311. }
  5312. return result;
  5313. }
  5314. int sendHeartbeatRequest(int gun_index)
  5315. {
  5316. mtrace();
  5317. int result = FAIL;
  5318. char message[80]={0};
  5319. char guid[37]={0};
  5320. char tempdata[65]={0};
  5321. random_uuid(guid);
  5322. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5323. , MESSAGE_TYPE_CALL
  5324. , guid );
  5325. LWS_Send(message);
  5326. sprintf(tempdata, "Heartbeat,%d", 0);
  5327. 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*/)
  5328. {
  5329. result = PASS;
  5330. }
  5331. return result;
  5332. }
  5333. int sendStartTransactionRequest(int gun_index)
  5334. {
  5335. mtrace();
  5336. int result = FAIL;
  5337. char message[250]={0};
  5338. char guid[37]={0};
  5339. struct timeval tmnow;
  5340. struct tm *tm;
  5341. char buf[28];//, usec_buf[6];
  5342. char tempdata[65]={0};
  5343. int tempIndex = 0;
  5344. DEBUG_INFO("sendStartTransactionRequest...\n");
  5345. gettimeofday(&tmnow, NULL);
  5346. time_t t;
  5347. t = time(NULL);
  5348. /*UTC time and date*/
  5349. tm = gmtime(&t);
  5350. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5351. #if 0 // remove temporally
  5352. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5353. strcat(buf,".");
  5354. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5355. strcat(buf,usec_buf);
  5356. #endif
  5357. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5358. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5359. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5360. // clear StartTransaction Response
  5361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5363. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5364. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5365. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5366. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5367. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5368. {
  5369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5370. {
  5371. tempIndex = ((gun_index==2) ? 1: 0);
  5372. }
  5373. else
  5374. {
  5375. tempIndex = gun_index;
  5376. }
  5377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5378. {
  5379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5380. {
  5381. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5382. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5383. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5384. }
  5385. }
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < CCS_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5400. {
  5401. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5402. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5403. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5404. }
  5405. }
  5406. }
  5407. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5408. {
  5409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5410. {
  5411. tempIndex = ((gun_index==2) ? 1: 0);
  5412. }
  5413. else
  5414. {
  5415. tempIndex = gun_index;
  5416. }
  5417. for (int index = 0; index < GB_QUANTITY; index++)
  5418. {
  5419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5420. {
  5421. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5422. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5423. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5424. }
  5425. }
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_DO)
  5428. {
  5429. tempIndex = gun_index;
  5430. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5431. {
  5432. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5433. {
  5434. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5435. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5436. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5437. }
  5438. }
  5439. }
  5440. else
  5441. {
  5442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5443. {
  5444. tempIndex = 2;
  5445. }
  5446. else
  5447. {
  5448. tempIndex = gun_index;
  5449. }
  5450. for (int index = 0; index < AC_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5453. {
  5454. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5455. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5456. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5457. }
  5458. }
  5459. }
  5460. random_uuid(guid);
  5461. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5462. {
  5463. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5464. , gun_index +1
  5465. , MESSAGE_TYPE_CALL
  5466. , guid
  5467. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5468. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5469. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5470. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5471. }
  5472. else
  5473. {
  5474. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5475. , gun_index +1
  5476. , MESSAGE_TYPE_CALL
  5477. , guid
  5478. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5479. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5480. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5481. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5482. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5483. }
  5484. #if 1
  5485. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5486. 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*/)
  5487. {
  5488. result = PASS;
  5489. }
  5490. #endif
  5491. strcpy(queuedata, message);
  5492. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5493. OCPP_insert_transaction_msg(YES, queuedata);
  5494. return result;
  5495. }
  5496. int sendStatusNotificationRequest(int gun_index)
  5497. {
  5498. mtrace();
  5499. int result = FAIL;
  5500. char message[600]={0};
  5501. char guid[37];
  5502. int currentStatus = 0;
  5503. struct timeval tmnow;
  5504. struct tm *tm;
  5505. char buf[28];//, usec_buf[6];
  5506. char tempdata[65]={0};
  5507. int tempIndex = 0;
  5508. uint8_t isStateChanged = TRUE;
  5509. uint8_t isContentIllegal = TRUE;
  5510. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5511. gettimeofday(&tmnow, NULL);
  5512. time_t t;
  5513. t = time(NULL);
  5514. /*UTC time and date*/
  5515. tm = gmtime(&t);
  5516. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5517. #if 0 // remove temporally
  5518. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5519. strcat(buf,".");
  5520. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5521. strcat(buf,usec_buf);
  5522. #endif
  5523. //printf("%s",buf);
  5524. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5525. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5526. // it's option
  5527. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5528. /*
  5529. enum _SYSTEM_STATUS
  5530. {
  5531. S_BOOTING = 0,
  5532. S_IDLE, = 1
  5533. S_AUTHORIZING, =2
  5534. S_REASSIGN_CHECK, =3
  5535. S_REASSIGN, =4
  5536. S_PRECHARGE, =5
  5537. S_PREPARING_FOR_EV, =6
  5538. S_PREPARING_FOR_EVSE, =7
  5539. S_CHARGING, =8
  5540. S_TERMINATING, =9
  5541. S_COMPLETE, =10
  5542. S_ALARM, =11
  5543. S_FAULT =12
  5544. }
  5545. */
  5546. //check Transaction active
  5547. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5548. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5549. {
  5550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5551. {
  5552. tempIndex = ((gun_index==2) ? 1: 0);
  5553. }
  5554. else
  5555. {
  5556. tempIndex = gun_index;
  5557. }
  5558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5559. {
  5560. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5561. {
  5562. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5563. {
  5564. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5565. {
  5566. currentStatus = Preparing; //OCPP Status: Preparing
  5567. }
  5568. else
  5569. {
  5570. currentStatus = Available; //OCPP Status: Available
  5571. }
  5572. }
  5573. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5574. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5575. ) //S_PRECHARGE
  5576. {
  5577. currentStatus = Preparing; //OCPP Status: Preparing
  5578. }
  5579. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5580. {
  5581. currentStatus = Charging; //OCPP Status: Charging
  5582. }
  5583. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5584. {
  5585. currentStatus = Finishing; //OCPP Status: Finishing
  5586. }
  5587. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5588. {
  5589. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5590. }
  5591. 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
  5592. {
  5593. currentStatus = Unavailable; //OCPP Status: Unavailable
  5594. }
  5595. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5596. {
  5597. currentStatus = Faulted; //OCPP Status: Faulted
  5598. }
  5599. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5600. {
  5601. currentStatus = Reserved; //OCPP Status: Reserved
  5602. }
  5603. } //end of the same index
  5604. }//end of for CHAdeMO_QUANTITY
  5605. }
  5606. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5607. {
  5608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5609. {
  5610. tempIndex = ((gun_index==2) ? 1: 0);
  5611. }
  5612. else
  5613. {
  5614. tempIndex = gun_index;
  5615. }
  5616. for (int index = 0; index < CCS_QUANTITY; index++)
  5617. {
  5618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5619. {
  5620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5621. {
  5622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5623. {
  5624. currentStatus = Preparing; //OCPP Status: Preparing
  5625. }
  5626. else
  5627. {
  5628. currentStatus = Available; //OCPP Status: Available
  5629. }
  5630. }
  5631. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5632. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5633. ) //S_PRECHARGE
  5634. {
  5635. currentStatus = Preparing; //OCPP Status: Preparing
  5636. }
  5637. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5638. {
  5639. currentStatus = Charging; //OCPP Status: Charging
  5640. }
  5641. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5642. {
  5643. currentStatus = Finishing; //OCPP Status: Finishing
  5644. }
  5645. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5646. {
  5647. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5648. }
  5649. 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
  5650. {
  5651. currentStatus = Unavailable; //OCPP Status : Unavailable
  5652. }
  5653. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5654. {
  5655. currentStatus = Faulted; //OCPP Status: Faulted
  5656. }
  5657. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5658. {
  5659. currentStatus = Reserved; //OCPP Status: Reserved
  5660. }
  5661. } //end of the same index
  5662. } // end of for CCS_QUANTITY
  5663. }
  5664. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5667. {
  5668. tempIndex = ((gun_index==2) ? 1: 0);
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < GB_QUANTITY; index++)
  5675. {
  5676. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5679. {
  5680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5681. {
  5682. currentStatus = Preparing; //OCPP Status: Preparing
  5683. }
  5684. else
  5685. {
  5686. currentStatus = Available; //OCPP Status: Available
  5687. }
  5688. }
  5689. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5690. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5691. ) //S_PRECHARGE
  5692. {
  5693. currentStatus = Preparing; //OCPP Status: Preparing
  5694. }
  5695. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5696. {
  5697. currentStatus = Charging; //OCPP Status: Charging
  5698. }
  5699. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5700. {
  5701. currentStatus = Finishing; //OCPP Status: Finishing
  5702. }
  5703. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5704. {
  5705. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5706. }
  5707. 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
  5708. {
  5709. currentStatus = Unavailable; //OCPP Status: Unavailable
  5710. }
  5711. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5712. {
  5713. currentStatus = Faulted; //OCPP Status: Faulted
  5714. }
  5715. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5716. {
  5717. currentStatus = Reserved; //OCPP Status: Reserved
  5718. }
  5719. } //end of the same index
  5720. } // end of for GB_QUANTITY
  5721. }
  5722. else if(gunType[gun_index] == GUN_TYPE_DO)
  5723. {
  5724. tempIndex = gun_index;
  5725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5726. {
  5727. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5730. {
  5731. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5732. {
  5733. currentStatus = Preparing; //OCPP Status: Preparing
  5734. }
  5735. else
  5736. {
  5737. currentStatus = Available; //OCPP Status: Available
  5738. }
  5739. }
  5740. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5741. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5742. ) //S_PRECHARGE
  5743. {
  5744. currentStatus = Preparing; //OCPP Status: Preparing
  5745. }
  5746. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5747. {
  5748. currentStatus = Charging; //OCPP Status: Charging
  5749. }
  5750. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5751. {
  5752. currentStatus = Finishing; //OCPP Status: Finishing
  5753. }
  5754. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5755. {
  5756. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5757. }
  5758. 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
  5759. {
  5760. currentStatus = Unavailable; //OCPP Status: Unavailable
  5761. }
  5762. 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
  5763. {
  5764. currentStatus = Faulted; //OCPP Status: Faulted
  5765. }
  5766. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5767. {
  5768. currentStatus = Reserved; //OCPP Status: Reserved
  5769. }
  5770. } //end of the same index
  5771. }
  5772. }
  5773. else
  5774. {
  5775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5776. {
  5777. tempIndex = 2;
  5778. }
  5779. else
  5780. {
  5781. tempIndex = gun_index;
  5782. }
  5783. for (int index = 0; index < AC_QUANTITY; index++)
  5784. {
  5785. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5786. {
  5787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5788. {
  5789. 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))
  5790. {
  5791. currentStatus = Preparing; //OCPP Status: Preparing
  5792. }
  5793. else
  5794. {
  5795. currentStatus = Available; //OCPP Status: Available
  5796. }
  5797. }
  5798. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5799. {
  5800. currentStatus = Preparing; //OCPP Status: Preparing
  5801. }
  5802. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5803. {
  5804. currentStatus = Charging; //OCPP Status: Charging
  5805. }
  5806. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5807. {
  5808. currentStatus = Finishing; //OCPP Status: Finishing
  5809. }
  5810. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5811. {
  5812. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5813. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5814. else
  5815. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5816. }
  5817. 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
  5818. {
  5819. currentStatus = Unavailable; //OCPP Status: Unavailable
  5820. }
  5821. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5822. {
  5823. currentStatus = Faulted; //OCPP Status: Faulted
  5824. }
  5825. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5826. {
  5827. currentStatus = Reserved; //OCPP Status: Reserved
  5828. }
  5829. }//end of the same index
  5830. }//end of for AC_QUANTITY
  5831. }
  5832. //it's option
  5833. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5834. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5835. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5836. {
  5837. isStateChanged = FALSE;
  5838. }
  5839. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5840. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5841. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5842. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5843. isContentIllegal = TRUE;
  5844. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5845. {
  5846. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5847. {
  5848. isContentIllegal = FALSE;
  5849. break;
  5850. }
  5851. }
  5852. if(isContentIllegal)
  5853. {
  5854. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5855. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5856. }
  5857. random_uuid(guid);
  5858. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5859. , MESSAGE_TYPE_CALL
  5860. , guid
  5861. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5862. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5863. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5864. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5865. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5866. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5867. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5868. if((server_sign == TRUE) && isStateChanged)
  5869. {
  5870. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5871. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5872. LWS_Send(message);
  5873. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5874. 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*/)
  5875. {
  5876. //DEBUG_ERROR("statusNotification mapitem pass");
  5877. result = PASS;
  5878. }
  5879. }
  5880. else
  5881. {
  5882. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5883. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5884. result = PASS;
  5885. }
  5886. return result;
  5887. }
  5888. int sendStopTransactionRequest(int gun_index)
  5889. {
  5890. mtrace();
  5891. int result = FAIL;
  5892. //char message[1500]={0};
  5893. char guid[37]={0};
  5894. char tempdata[65]={0};
  5895. int tempIndex = 0;
  5896. char TempStopTransaction[256];
  5897. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5898. //int idx_sample=0;
  5899. DEBUG_INFO("sendStopTransactionRequest \n");
  5900. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5901. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5902. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5905. {
  5906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5907. {
  5908. tempIndex = ((gun_index==2) ? 1: 0);
  5909. }
  5910. else
  5911. {
  5912. tempIndex = gun_index;
  5913. }
  5914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5915. {
  5916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5917. {
  5918. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5919. }
  5920. }// END OF CHAdeMO_QUANTITY
  5921. }
  5922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5923. {
  5924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5925. {
  5926. tempIndex = ((gun_index==2) ? 1: 0);
  5927. }
  5928. else
  5929. {
  5930. tempIndex = gun_index;
  5931. }
  5932. for (int index = 0; index < CCS_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5935. {
  5936. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5937. }
  5938. }// END OF CCS_QUANTITY
  5939. }
  5940. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5941. {
  5942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5943. {
  5944. tempIndex = ((gun_index==2) ? 1: 0);
  5945. }
  5946. else
  5947. {
  5948. tempIndex = gun_index;
  5949. }
  5950. for (int index = 0; index < GB_QUANTITY; index++)
  5951. {
  5952. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5953. {
  5954. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5955. }
  5956. }// END OF GB_QUANTITY
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_DO)
  5959. {
  5960. tempIndex = gun_index;
  5961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5964. {
  5965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5966. }
  5967. }// END OF GB_QUANTITY
  5968. }
  5969. else
  5970. {
  5971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5972. {
  5973. tempIndex = 2;
  5974. }
  5975. else
  5976. {
  5977. tempIndex = gun_index;
  5978. }
  5979. for (int index = 0; index < AC_QUANTITY; index++)
  5980. {
  5981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5982. {
  5983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5984. }
  5985. }// END OF AC_QUANTITY
  5986. }
  5987. //====================================== Stop Transaction Time =====================================================
  5988. struct timeval tmnow;
  5989. struct tm *tm;
  5990. char buf[28];//, usec_buf[6];
  5991. gettimeofday(&tmnow, NULL);
  5992. time_t t;
  5993. t = time(NULL);
  5994. /*UTC time and date*/
  5995. tm = gmtime(&t);
  5996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5999. random_uuid(guid);
  6000. /***********************************transactionData******************************************************/
  6001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6003. //=================================
  6004. // Transaction_Begin
  6005. //=================================
  6006. //=================================
  6007. // Transaction_End
  6008. //=================================
  6009. // ================================= Current.Import L1 ===============================================
  6010. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6011. {
  6012. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6013. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6014. {
  6015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6016. {
  6017. tempIndex = ((gun_index==2) ? 1: 0);
  6018. }
  6019. else
  6020. {
  6021. tempIndex = gun_index;
  6022. }
  6023. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6024. {
  6025. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6026. {
  6027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6028. }
  6029. }// End of for CHAdeMO_QUANTITY
  6030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6031. }
  6032. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6033. {
  6034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6035. {
  6036. tempIndex = ((gun_index==2) ? 1: 0);
  6037. }
  6038. else
  6039. {
  6040. tempIndex = gun_index;
  6041. }
  6042. for (int index = 0; index < CCS_QUANTITY; index++)
  6043. {
  6044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6045. {
  6046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6047. }
  6048. }// End of for CCS_QUANTITY
  6049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6050. }
  6051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < GB_QUANTITY; index++)
  6062. {
  6063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6064. {
  6065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6066. }
  6067. }// End of for GB_QUANTITY
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6069. }
  6070. else if(gunType[gun_index] == GUN_TYPE_DO)
  6071. {
  6072. tempIndex = gun_index;
  6073. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6074. {
  6075. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6076. {
  6077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6078. }
  6079. }
  6080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6081. }
  6082. else
  6083. {
  6084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6085. {
  6086. tempIndex = 2;
  6087. }
  6088. else
  6089. {
  6090. tempIndex = gun_index;
  6091. }
  6092. for (int index = 0; index < AC_QUANTITY; index++)
  6093. {
  6094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6095. {
  6096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6097. }
  6098. }// End of for AC_QUANTITY
  6099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6100. }
  6101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6106. }
  6107. // ================================= Energy.Active.Import.Interval ==============================================
  6108. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6109. {
  6110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6112. {
  6113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6114. {
  6115. tempIndex = ((gun_index==2) ? 1: 0);
  6116. }
  6117. else
  6118. {
  6119. tempIndex = gun_index;
  6120. }
  6121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6124. {
  6125. 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
  6126. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6127. }
  6128. }// END OF CHAdeMO_QUANTITY
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6132. {
  6133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6134. {
  6135. tempIndex = ((gun_index==2) ? 1: 0);
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. for (int index = 0; index < CCS_QUANTITY; index++)
  6142. {
  6143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6144. {
  6145. 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
  6146. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6147. }
  6148. }// END OF CCS_QUANTITY
  6149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6150. }
  6151. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6154. {
  6155. tempIndex = ((gun_index==2) ? 1: 0);
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < GB_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6164. {
  6165. 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
  6166. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6167. }
  6168. }// END OF GB_QUANTITY
  6169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6170. }
  6171. else if(gunType[gun_index] == GUN_TYPE_DO)
  6172. {
  6173. tempIndex = gun_index;
  6174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6175. {
  6176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6177. {
  6178. 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
  6179. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6180. }
  6181. }
  6182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6183. }
  6184. else
  6185. {
  6186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6187. {
  6188. tempIndex = 2;
  6189. }
  6190. else
  6191. {
  6192. tempIndex = gun_index;
  6193. }
  6194. for (int index = 0; index < AC_QUANTITY; index++)
  6195. {
  6196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6197. {
  6198. 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
  6199. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6200. }
  6201. }// END OF AC_QUANTITY
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6203. }
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6209. }
  6210. //=================================== Power.Active.Import ==================================================
  6211. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6212. {
  6213. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6215. {
  6216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6217. {
  6218. tempIndex = ((gun_index==2) ? 1: 0);
  6219. }
  6220. else
  6221. {
  6222. tempIndex = gun_index;
  6223. }
  6224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6229. }
  6230. } // End for CHAdeMO_QUANTITY
  6231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6232. }
  6233. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6234. {
  6235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6236. {
  6237. tempIndex = ((gun_index==2) ? 1: 0);
  6238. }
  6239. else
  6240. {
  6241. tempIndex = gun_index;
  6242. }
  6243. for (int index = 0; index < CCS_QUANTITY; index++)
  6244. {
  6245. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6246. {
  6247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6248. }
  6249. } // END for CCS_QUANTITY
  6250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6251. }
  6252. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6253. {
  6254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6255. {
  6256. tempIndex = ((gun_index==2) ? 1: 0);
  6257. }
  6258. else
  6259. {
  6260. tempIndex = gun_index;
  6261. }
  6262. for (int index = 0; index < GB_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6265. {
  6266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6267. }
  6268. }// END for GB_QUANTITY
  6269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6270. }
  6271. else if(gunType[gun_index] == GUN_TYPE_DO)
  6272. {
  6273. tempIndex = gun_index;
  6274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6275. {
  6276. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6277. {
  6278. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6279. }
  6280. }
  6281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6282. }
  6283. else
  6284. {
  6285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6286. {
  6287. tempIndex = 2;
  6288. }
  6289. else
  6290. {
  6291. tempIndex = gun_index;
  6292. }
  6293. for (int index = 0; index < AC_QUANTITY; index++)
  6294. {
  6295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6296. {
  6297. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6298. }
  6299. } // END for AC_QUANTITY
  6300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6301. }
  6302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6307. }
  6308. //============================ Voltage L1 ====================================
  6309. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6310. {
  6311. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6312. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6313. {
  6314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6315. {
  6316. tempIndex = ((gun_index==2) ? 1: 0);
  6317. }
  6318. else
  6319. {
  6320. tempIndex = gun_index;
  6321. }
  6322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6323. {
  6324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6325. {
  6326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6327. }
  6328. } // END OF FOR CHAdeMO_QUANTITY
  6329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6330. }
  6331. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6332. {
  6333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6334. {
  6335. tempIndex = ((gun_index==2) ? 1: 0);
  6336. }
  6337. else
  6338. {
  6339. tempIndex = gun_index;
  6340. }
  6341. for (int index = 0; index < CCS_QUANTITY; index++)
  6342. {
  6343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6344. {
  6345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6346. }
  6347. } // END OF FOR CCS_QUANTITY
  6348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6349. }
  6350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6351. {
  6352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6353. {
  6354. tempIndex = ((gun_index==2) ? 1: 0);
  6355. }
  6356. else
  6357. {
  6358. tempIndex = gun_index;
  6359. }
  6360. for (int index = 0; index < GB_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6365. }
  6366. } // END OF FOR GB_QUANTITY
  6367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6368. }
  6369. else if(gunType[gun_index] == GUN_TYPE_DO)
  6370. {
  6371. tempIndex = gun_index;
  6372. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6375. {
  6376. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6380. }
  6381. else
  6382. {
  6383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6384. {
  6385. tempIndex = 2;
  6386. }
  6387. else
  6388. {
  6389. tempIndex = gun_index;
  6390. }
  6391. for (int index = 0; index < AC_QUANTITY; index++)
  6392. {
  6393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6394. {
  6395. 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
  6396. }
  6397. } // END OF FOR AC_QUANTITY
  6398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6399. }
  6400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6405. }
  6406. //====================== End SoC ================================
  6407. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6408. {
  6409. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6410. 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))
  6411. {
  6412. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6413. {
  6414. tempIndex = ((gun_index==2) ? 1: 0);
  6415. }
  6416. else
  6417. {
  6418. tempIndex = gun_index;
  6419. }
  6420. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6421. {
  6422. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6425. {
  6426. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6427. }
  6428. }
  6429. }
  6430. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6431. {
  6432. for (int index = 0; index < CCS_QUANTITY; index++)
  6433. {
  6434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6435. {
  6436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6437. }
  6438. }
  6439. }
  6440. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6441. {
  6442. for (int index = 0; index < GB_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6447. }
  6448. }
  6449. }
  6450. else if(gunType[gun_index] == GUN_TYPE_DO)
  6451. {
  6452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6453. {
  6454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6455. {
  6456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6457. }
  6458. }
  6459. }
  6460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6466. } // END FOR DC CASE
  6467. }
  6468. // ================================= Current.Import L2 ===============================================
  6469. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6470. {
  6471. // AC 3 phse L2 current
  6472. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6473. {
  6474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6475. {
  6476. tempIndex = 2;
  6477. }
  6478. else
  6479. {
  6480. tempIndex = gun_index;
  6481. }
  6482. for (int index = 0; index < AC_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6487. }
  6488. }// End of for AC_QUANTITY
  6489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6490. }
  6491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6496. }
  6497. // ================================= Current.Import L3 ===============================================
  6498. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6499. {
  6500. // AC 3 phse L3 current
  6501. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6502. {
  6503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6504. {
  6505. tempIndex = 2;
  6506. }
  6507. else
  6508. {
  6509. tempIndex = gun_index;
  6510. }
  6511. for (int index = 0; index < AC_QUANTITY; index++)
  6512. {
  6513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6514. {
  6515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6516. }
  6517. }// End of for AC_QUANTITY
  6518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6519. }
  6520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6525. }
  6526. //============================ Voltage L2 ====================================
  6527. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6528. {
  6529. // AC 3 phse L2 voltage
  6530. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6531. {
  6532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6533. {
  6534. tempIndex = 2;
  6535. }
  6536. else
  6537. {
  6538. tempIndex = gun_index;
  6539. }
  6540. for (int index = 0; index < AC_QUANTITY; index++)
  6541. {
  6542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6543. {
  6544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6545. }
  6546. } // END OF FOR AC_QUANTITY
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6548. }
  6549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6554. }
  6555. //============================ Voltage L3 ====================================
  6556. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6557. {
  6558. // AC 3 phse L3 voltage
  6559. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6562. {
  6563. tempIndex = 2;
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < AC_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6572. {
  6573. 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
  6574. }
  6575. } // END OF FOR AC_QUANTITY
  6576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6577. }
  6578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6583. }
  6584. //====================== Start SoC ================================
  6585. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6586. {
  6587. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6588. 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))
  6589. {
  6590. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6591. {
  6592. tempIndex = ((gun_index==2) ? 1: 0);
  6593. }
  6594. else
  6595. {
  6596. tempIndex = gun_index;
  6597. }
  6598. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6599. {
  6600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6603. {
  6604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6605. }
  6606. }
  6607. }
  6608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6609. {
  6610. for (int index = 0; index < CCS_QUANTITY; index++)
  6611. {
  6612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6613. {
  6614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6615. }
  6616. }
  6617. }
  6618. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6619. {
  6620. for (int index = 0; index < GB_QUANTITY; index++)
  6621. {
  6622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6623. {
  6624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6625. }
  6626. }
  6627. }
  6628. else if(gunType[gun_index] == GUN_TYPE_DO)
  6629. {
  6630. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6631. {
  6632. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6633. {
  6634. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6635. }
  6636. }
  6637. }
  6638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6644. } // END FOR DC CASE
  6645. }
  6646. //================================================ Message create ====================================================
  6647. json_object *StopTransaction = json_object_new_object();
  6648. json_object *transactionDatas = json_object_new_array();
  6649. json_object *sampledValues = json_object_new_array();
  6650. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6651. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6652. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6653. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6654. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6655. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6656. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6657. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6658. {
  6659. json_object *transactionData = json_object_new_object();
  6660. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6661. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6662. {
  6663. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6664. {
  6665. json_object *sampledValue = json_object_new_object();
  6666. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6667. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6668. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6669. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6670. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6671. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6672. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6673. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6674. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6675. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6676. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6677. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6678. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6679. json_object_array_add(sampledValues, sampledValue);
  6680. }
  6681. }
  6682. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6683. json_object_array_add(transactionDatas, transactionData);
  6684. }
  6685. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6686. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6687. ,MESSAGE_TYPE_CALL
  6688. ,guid
  6689. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6690. json_object_put(StopTransaction);
  6691. #if 1 // for TempStopTransaction
  6692. //Delete TempStopTransaction
  6693. if((access(TempStopTransaction,F_OK))!=-1)
  6694. {
  6695. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6696. }
  6697. #endif
  6698. #if 1
  6699. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6700. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6701. {
  6702. result = PASS;
  6703. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6704. }
  6705. #endif
  6706. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6707. OCPP_insert_transaction_msg(NO, queuedata);
  6708. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6709. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6710. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6711. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6712. {
  6713. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6714. }
  6715. //for test
  6716. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6717. return result;
  6718. }
  6719. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6720. {
  6721. mtrace();
  6722. int result = FAIL;
  6723. char guid[37]={0};
  6724. char tempdata[65]={0};
  6725. int tempIndex = 0;
  6726. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6727. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6728. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6729. //set value
  6730. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6731. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6732. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6733. -1);
  6734. random_uuid(guid);
  6735. //UTC Date time
  6736. struct timeval tmnow;
  6737. struct tm *tm;
  6738. char buf[28];//, usec_buf[6];
  6739. gettimeofday(&tmnow, NULL);
  6740. time_t t;
  6741. t = time(NULL);
  6742. /*UTC time and date*/
  6743. tm = gmtime(&t);
  6744. if(dataType == ReadingContext_Sample_Clock)
  6745. {
  6746. struct tm *tmTarget;
  6747. struct timeb tbTarget;
  6748. tbTarget.time = mktime(tm);
  6749. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6750. tmTarget = gmtime(&tbTarget.time);
  6751. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6752. }
  6753. else
  6754. {
  6755. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6756. }
  6757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6758. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6759. //********************************(1)Current.Import L1************************************************/
  6760. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6761. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6762. (dataType == ReadingContext_Trigger))
  6763. {
  6764. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6765. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6766. {
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6768. {
  6769. tempIndex = ((gun_index==2) ? 1: 0);
  6770. }
  6771. else
  6772. {
  6773. tempIndex = gun_index;
  6774. }
  6775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6778. {
  6779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6780. }
  6781. }
  6782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6783. }
  6784. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6785. {
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6787. {
  6788. tempIndex = ((gun_index==2) ? 1: 0);
  6789. }
  6790. else
  6791. {
  6792. tempIndex = gun_index;
  6793. }
  6794. for (int index = 0; index < CCS_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6797. {
  6798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6799. }
  6800. }
  6801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6802. }
  6803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6804. {
  6805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6806. {
  6807. tempIndex = ((gun_index==2) ? 1: 0);
  6808. }
  6809. else
  6810. {
  6811. tempIndex = gun_index;
  6812. }
  6813. for (int index = 0; index < GB_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6816. {
  6817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6818. }
  6819. }
  6820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6821. }
  6822. else if(gunType[gun_index] == GUN_TYPE_DO)
  6823. {
  6824. tempIndex = gun_index;
  6825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6828. {
  6829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6833. }
  6834. else
  6835. {
  6836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6837. {
  6838. tempIndex = 2;
  6839. }
  6840. else
  6841. {
  6842. tempIndex = gun_index;
  6843. }
  6844. for (int index = 0; index < AC_QUANTITY; index++)
  6845. {
  6846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6847. {
  6848. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6849. }
  6850. }
  6851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6852. }
  6853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6858. }
  6859. //********************************(2)Energy.Active.Import.Register ************************************************/
  6860. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6861. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6862. (dataType == ReadingContext_Trigger))
  6863. {
  6864. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6865. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6866. {
  6867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6868. {
  6869. tempIndex = ((gun_index==2) ? 1: 0);
  6870. }
  6871. else
  6872. {
  6873. tempIndex = gun_index;
  6874. }
  6875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6876. {
  6877. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6878. {
  6879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6880. }
  6881. }
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6883. }
  6884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6885. {
  6886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6887. {
  6888. tempIndex = ((gun_index==2) ? 1: 0);
  6889. }
  6890. else
  6891. {
  6892. tempIndex = gun_index;
  6893. }
  6894. for (int index = 0; index < CCS_QUANTITY; index++)
  6895. {
  6896. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6897. {
  6898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6899. }
  6900. }
  6901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6902. }
  6903. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6904. {
  6905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6906. {
  6907. tempIndex = ((gun_index==2) ? 1: 0);
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. for (int index = 0; index < GB_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6916. {
  6917. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6921. }
  6922. else if(gunType[gun_index] == GUN_TYPE_DO)
  6923. {
  6924. tempIndex = gun_index;
  6925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6926. {
  6927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6928. {
  6929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6930. }
  6931. }
  6932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6933. }
  6934. else
  6935. {
  6936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6937. {
  6938. tempIndex = 2;
  6939. }
  6940. else
  6941. {
  6942. tempIndex = gun_index;
  6943. }
  6944. for (int index = 0; index < AC_QUANTITY; index++)
  6945. {
  6946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6947. {
  6948. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6949. }
  6950. }
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6952. }
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6958. }
  6959. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6960. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6961. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6962. (dataType == ReadingContext_Trigger))
  6963. {
  6964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6966. {
  6967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6968. {
  6969. tempIndex = ((gun_index==2) ? 1: 0);
  6970. }
  6971. else
  6972. {
  6973. tempIndex = gun_index;
  6974. }
  6975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6976. {
  6977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6978. {
  6979. if(dataType == ReadingContext_Sample_Clock)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6982. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6983. }
  6984. else if(dataType == ReadingContext_Sample_Periodic)
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6987. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6988. }
  6989. else
  6990. {
  6991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6992. }
  6993. }
  6994. } // END OF FOR CHAdeMO_QUANTITY
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6996. }
  6997. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6998. {
  6999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7000. {
  7001. tempIndex = ((gun_index==2) ? 1: 0);
  7002. }
  7003. else
  7004. {
  7005. tempIndex = gun_index;
  7006. }
  7007. for (int index = 0; index < CCS_QUANTITY; index++)
  7008. {
  7009. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7010. {
  7011. if(dataType == ReadingContext_Sample_Clock)
  7012. {
  7013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7014. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7015. }
  7016. else if(dataType == ReadingContext_Sample_Periodic)
  7017. {
  7018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7019. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7020. }
  7021. else
  7022. {
  7023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7024. }
  7025. }
  7026. } // END OF CCS_QUANTITY
  7027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7028. }
  7029. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7030. {
  7031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7032. {
  7033. tempIndex = ((gun_index==2) ? 1: 0);
  7034. }
  7035. else
  7036. {
  7037. tempIndex = gun_index;
  7038. }
  7039. for (int index = 0; index < GB_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7042. {
  7043. if(dataType == ReadingContext_Sample_Clock)
  7044. {
  7045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7046. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7047. }
  7048. else if(dataType == ReadingContext_Sample_Periodic)
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7051. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7052. }
  7053. else
  7054. {
  7055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7056. }
  7057. }
  7058. } // END OF GB_QUANTITY
  7059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7060. }
  7061. else if(gunType[gun_index] == GUN_TYPE_DO)
  7062. {
  7063. tempIndex = gun_index;
  7064. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7067. {
  7068. if(dataType == ReadingContext_Sample_Clock)
  7069. {
  7070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7071. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7072. }
  7073. else if(dataType == ReadingContext_Sample_Periodic)
  7074. {
  7075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7076. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7077. }
  7078. else
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7081. }
  7082. }
  7083. }
  7084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7085. }
  7086. else
  7087. {
  7088. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7089. {
  7090. tempIndex = 2;
  7091. }
  7092. else
  7093. {
  7094. tempIndex = gun_index;
  7095. }
  7096. for (int index = 0; index < AC_QUANTITY; index++)
  7097. {
  7098. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7099. {
  7100. if(dataType == ReadingContext_Sample_Clock)
  7101. {
  7102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7103. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7104. }
  7105. else if(dataType == ReadingContext_Sample_Periodic)
  7106. {
  7107. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7108. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7109. }
  7110. else
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7113. }
  7114. }
  7115. }
  7116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7117. }
  7118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7123. }
  7124. //********************************(4)Power.Active.Import************************************************/
  7125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7127. (dataType == ReadingContext_Trigger))
  7128. {
  7129. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7130. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7131. {
  7132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7133. {
  7134. tempIndex = ((gun_index==2) ? 1: 0);
  7135. }
  7136. else
  7137. {
  7138. tempIndex = gun_index;
  7139. }
  7140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7141. {
  7142. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7143. {
  7144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7145. }
  7146. } // END OF FOR
  7147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7148. }
  7149. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7150. {
  7151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7152. {
  7153. tempIndex = ((gun_index==2) ? 1: 0);
  7154. }
  7155. else
  7156. {
  7157. tempIndex = gun_index;
  7158. }
  7159. for (int index = 0; index < CCS_QUANTITY; index++)
  7160. {
  7161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7162. {
  7163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7164. }
  7165. }
  7166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7167. }
  7168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7169. {
  7170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7171. {
  7172. tempIndex = ((gun_index==2) ? 1: 0);
  7173. }
  7174. else
  7175. {
  7176. tempIndex = gun_index;
  7177. }
  7178. for (int index = 0; index < GB_QUANTITY; index++)
  7179. {
  7180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7181. {
  7182. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7184. }
  7185. }
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7187. }
  7188. else if(gunType[gun_index] == GUN_TYPE_DO)
  7189. {
  7190. tempIndex = gun_index;
  7191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7192. {
  7193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7194. {
  7195. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7196. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7197. }
  7198. }
  7199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7200. }
  7201. else
  7202. {
  7203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7204. {
  7205. tempIndex = 2;
  7206. }
  7207. else
  7208. {
  7209. tempIndex = gun_index;
  7210. }
  7211. for (int index = 0; index < AC_QUANTITY; index++)
  7212. {
  7213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7214. {
  7215. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7216. }
  7217. }
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7219. }
  7220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7225. }
  7226. //***********************************************(5)VOLTAGE L1******************************************************/
  7227. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7228. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7229. (dataType == ReadingContext_Trigger))
  7230. {
  7231. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7232. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7233. {
  7234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7235. {
  7236. tempIndex = ((gun_index==2) ? 1: 0);
  7237. }
  7238. else
  7239. {
  7240. tempIndex = gun_index;
  7241. }
  7242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7243. {
  7244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7245. {
  7246. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7250. }
  7251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7252. {
  7253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7254. {
  7255. tempIndex = ((gun_index==2) ? 1: 0);
  7256. }
  7257. else
  7258. {
  7259. tempIndex = gun_index;
  7260. }
  7261. for (int index = 0; index < CCS_QUANTITY; index++)
  7262. {
  7263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7264. {
  7265. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7266. }
  7267. }
  7268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7269. }
  7270. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7271. {
  7272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7273. {
  7274. tempIndex = ((gun_index==2) ? 1: 0);
  7275. }
  7276. else
  7277. {
  7278. tempIndex = gun_index;
  7279. }
  7280. for (int index = 0; index < GB_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7283. {
  7284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7285. }
  7286. }
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7288. }
  7289. else if(gunType[gun_index] == GUN_TYPE_DO)
  7290. {
  7291. tempIndex = gun_index;
  7292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7293. {
  7294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7295. {
  7296. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7297. }
  7298. }
  7299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7300. }
  7301. else
  7302. {
  7303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7304. {
  7305. tempIndex = 2;
  7306. }
  7307. else
  7308. {
  7309. tempIndex = gun_index;
  7310. }
  7311. for (int index = 0; index < AC_QUANTITY; index++)
  7312. {
  7313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7314. {
  7315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7316. }
  7317. }
  7318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7319. }
  7320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7325. }
  7326. //***********************************************(6)SOC******************************************************/
  7327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7329. (dataType == ReadingContext_Trigger))
  7330. {
  7331. 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))
  7332. {
  7333. //idx_sample=5;
  7334. //sampledValue = NULL;
  7335. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7336. {
  7337. tempIndex = ((gun_index==2) ? 1: 0);
  7338. }
  7339. else
  7340. {
  7341. tempIndex = gun_index;
  7342. }
  7343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7344. {
  7345. //tempIndex = ((gun_index==2) ? 1: 0);
  7346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7347. {
  7348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7349. {
  7350. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7351. }
  7352. }
  7353. }
  7354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7355. {
  7356. //tempIndex = ((gun_index==2) ? 1: 0);
  7357. for (int index = 0; index < CCS_QUANTITY; index++)
  7358. {
  7359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7360. {
  7361. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7362. }
  7363. }
  7364. }
  7365. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7366. {
  7367. //tempIndex = ((gun_index==2) ? 1: 0);
  7368. for (int index = 0; index < GB_QUANTITY; index++)
  7369. {
  7370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7371. {
  7372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7373. }
  7374. }
  7375. }
  7376. else if(gunType[gun_index] == GUN_TYPE_DO)
  7377. {
  7378. //tempIndex = ((gun_index==2) ? 1: 0);
  7379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7382. {
  7383. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7384. }
  7385. }
  7386. }
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7393. }
  7394. }
  7395. //********************************(7)Current.Import L2************************************************/
  7396. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7397. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7398. (dataType == ReadingContext_Trigger))
  7399. {
  7400. // Only for AC 3 phase
  7401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7402. {
  7403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7404. {
  7405. tempIndex = 2;
  7406. }
  7407. else
  7408. {
  7409. tempIndex = gun_index;
  7410. }
  7411. for (int index = 0; index < AC_QUANTITY; index++)
  7412. {
  7413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7414. {
  7415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7416. }
  7417. }
  7418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7419. }
  7420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7425. }
  7426. //********************************(8)Current.Import L3************************************************/
  7427. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7428. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7429. (dataType == ReadingContext_Trigger))
  7430. {
  7431. // Only for AC 3 phase
  7432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7433. {
  7434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7435. {
  7436. tempIndex = 2;
  7437. }
  7438. else
  7439. {
  7440. tempIndex = gun_index;
  7441. }
  7442. for (int index = 0; index < AC_QUANTITY; index++)
  7443. {
  7444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7445. {
  7446. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7447. }
  7448. }
  7449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7450. }
  7451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7456. }
  7457. //***********************************************(9)VOLTAGE L2******************************************************/
  7458. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7459. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7460. (dataType == ReadingContext_Trigger))
  7461. {
  7462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7463. {
  7464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7465. {
  7466. tempIndex = 2;
  7467. }
  7468. else
  7469. {
  7470. tempIndex = gun_index;
  7471. }
  7472. for (int index = 0; index < AC_QUANTITY; index++)
  7473. {
  7474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7475. {
  7476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7477. }
  7478. }
  7479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7480. }
  7481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7486. }
  7487. //***********************************************(10)VOLTAGE L3******************************************************/
  7488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7490. (dataType == ReadingContext_Trigger))
  7491. {
  7492. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7493. {
  7494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7495. {
  7496. tempIndex = 2;
  7497. }
  7498. else
  7499. {
  7500. tempIndex = gun_index;
  7501. }
  7502. for (int index = 0; index < AC_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7505. {
  7506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7507. }
  7508. }
  7509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7510. }
  7511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7516. }
  7517. //***********************************************(11)Current.Offered******************************************************/
  7518. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7519. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7520. (dataType == ReadingContext_Trigger))
  7521. {
  7522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7524. {
  7525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7526. {
  7527. tempIndex = ((gun_index==2) ? 1: 0);
  7528. }
  7529. else
  7530. {
  7531. tempIndex = gun_index;
  7532. }
  7533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7536. {
  7537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7538. }
  7539. } // END OF FOR CHAdeMO_QUANTITY
  7540. }
  7541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7542. {
  7543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7544. {
  7545. tempIndex = ((gun_index==2) ? 1: 0);
  7546. }
  7547. else
  7548. {
  7549. tempIndex = gun_index;
  7550. }
  7551. for (int index = 0; index < CCS_QUANTITY; index++)
  7552. {
  7553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7554. {
  7555. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7556. }
  7557. } // END OF CCS_QUANTITY
  7558. }
  7559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7560. {
  7561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7562. {
  7563. tempIndex = ((gun_index==2) ? 1: 0);
  7564. }
  7565. else
  7566. {
  7567. tempIndex = gun_index;
  7568. }
  7569. for (int index = 0; index < GB_QUANTITY; index++)
  7570. {
  7571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7572. {
  7573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7574. }
  7575. } // END OF GB_QUANTITY
  7576. }
  7577. else if(gunType[gun_index] == GUN_TYPE_DO)
  7578. {
  7579. tempIndex = gun_index;
  7580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7581. {
  7582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7583. {
  7584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7585. }
  7586. }
  7587. }
  7588. else
  7589. {
  7590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7591. {
  7592. tempIndex = 2;
  7593. }
  7594. else
  7595. {
  7596. tempIndex = gun_index;
  7597. }
  7598. for (int index = 0; index < AC_QUANTITY; index++)
  7599. {
  7600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7601. {
  7602. uint16_t currentOffer;
  7603. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7604. {
  7605. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7606. }
  7607. else
  7608. {
  7609. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7610. }
  7611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7612. }
  7613. }
  7614. }
  7615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7620. }
  7621. //***********************************************(12)Power.Offered******************************************************/
  7622. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7623. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7624. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7625. {
  7626. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7627. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7628. {
  7629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7630. {
  7631. tempIndex = ((gun_index==2) ? 1: 0);
  7632. }
  7633. else
  7634. {
  7635. tempIndex = gun_index;
  7636. }
  7637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7638. {
  7639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7640. {
  7641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7642. }
  7643. } // END OF FOR CHAdeMO_QUANTITY
  7644. }
  7645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7646. {
  7647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7648. {
  7649. tempIndex = ((gun_index==2) ? 1: 0);
  7650. }
  7651. else
  7652. {
  7653. tempIndex = gun_index;
  7654. }
  7655. for (int index = 0; index < CCS_QUANTITY; index++)
  7656. {
  7657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7658. {
  7659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7660. }
  7661. } // END OF CCS_QUANTITY
  7662. }
  7663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7664. {
  7665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7666. {
  7667. tempIndex = ((gun_index==2) ? 1: 0);
  7668. }
  7669. else
  7670. {
  7671. tempIndex = gun_index;
  7672. }
  7673. for (int index = 0; index < GB_QUANTITY; index++)
  7674. {
  7675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7676. {
  7677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7678. }
  7679. } // END OF GB_QUANTITY
  7680. }
  7681. else if(gunType[gun_index] == GUN_TYPE_DO)
  7682. {
  7683. tempIndex = gun_index;
  7684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7685. {
  7686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7687. {
  7688. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7689. }
  7690. }
  7691. }
  7692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7696. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7697. }
  7698. // Message create ====================================================================================================
  7699. if(TRUE)
  7700. {
  7701. json_object *MeterValueReq = json_object_new_object();
  7702. json_object *MeterValues = json_object_new_array();
  7703. json_object *sampledValues = json_object_new_array();
  7704. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7705. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7706. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7707. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7708. {
  7709. json_object *MeterValue = json_object_new_object();
  7710. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7711. {
  7712. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7713. {
  7714. json_object *sampledValue = json_object_new_object();
  7715. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7716. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7717. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7718. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7719. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7720. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7721. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7722. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7723. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7724. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7725. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7726. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7727. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7728. json_object_array_add(sampledValues, sampledValue);
  7729. }
  7730. }
  7731. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7732. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7733. json_object_array_add(MeterValues, MeterValue);
  7734. }
  7735. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7736. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7737. ,gun_index + 1
  7738. ,MESSAGE_TYPE_CALL
  7739. ,guid
  7740. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7741. json_object_put(MeterValueReq);
  7742. }
  7743. // Put request guid to hash map
  7744. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7745. 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*/)
  7746. {
  7747. result = PASS;
  7748. //DEBUG_INFO("MeterValues mapitem pass\n");
  7749. }
  7750. if((dataType != ReadingContext_Trigger) &&
  7751. (dataType != ReadingContext_Sample_Clock) &&
  7752. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7753. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7754. else
  7755. {
  7756. if(FirstHeartBeat)
  7757. LWS_Send(queuedata +2);
  7758. }
  7759. return result;
  7760. }
  7761. int sendLogStatusNotificationRequest(char *status)
  7762. {
  7763. mtrace();
  7764. int result = PASS;
  7765. char message[4096]={0};
  7766. char guid[37]={0};
  7767. char tempdata[128]={0};
  7768. json_object *LogStatusNotification = json_object_new_object();
  7769. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7770. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7771. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7772. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7773. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7774. random_uuid(guid);
  7775. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7776. json_object_put(LogStatusNotification);
  7777. LWS_Send(message);
  7778. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7779. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7780. {
  7781. result = PASS;
  7782. }
  7783. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7784. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7785. return result;
  7786. }
  7787. int sendSecurityEventNotificationRequest()
  7788. {
  7789. mtrace();
  7790. int result = PASS;
  7791. char message[4096]={0};
  7792. char guid[37]={0};
  7793. char tempdata[128]={0};
  7794. json_object *SecurityEventNotification = json_object_new_object();
  7795. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7796. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7797. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7798. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7799. random_uuid(guid);
  7800. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7801. json_object_put(SecurityEventNotification);
  7802. LWS_Send(message);
  7803. sprintf(tempdata, "SecurityEventNotification,0");
  7804. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7805. {
  7806. result = PASS;
  7807. }
  7808. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7809. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7810. return result;
  7811. }
  7812. int sendSignCertificateRequest()
  7813. {
  7814. mtrace();
  7815. int result = PASS;
  7816. char message[4096]={0};
  7817. char guid[37]={0};
  7818. char tempdata[128]={0};
  7819. json_object *SignCertificate = json_object_new_object();
  7820. DEBUG_INFO("sendSignCertificateRequest...\n");
  7821. // Read csr file content
  7822. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7823. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7824. char *line = NULL;
  7825. size_t len = 0;
  7826. while(getline(&line, &len, fp) != -1)
  7827. {
  7828. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7829. {
  7830. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7831. }
  7832. }
  7833. fclose(fp);
  7834. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7835. random_uuid(guid);
  7836. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7837. json_object_put(SignCertificate);
  7838. LWS_Send(message);
  7839. sprintf(tempdata, "SignCertificate,0");
  7840. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7841. {
  7842. result = PASS;
  7843. }
  7844. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7845. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7846. return result;
  7847. }
  7848. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7849. {
  7850. mtrace();
  7851. int result = PASS;
  7852. char message[110]={0};
  7853. char guid[37]={0};
  7854. char tempdata[65]={0};
  7855. json_object *FirmwareStatusNotification = json_object_new_object();
  7856. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7857. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7858. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7859. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7860. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7861. random_uuid(guid);
  7862. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7863. json_object_put(FirmwareStatusNotification);
  7864. LWS_Send(message);
  7865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7866. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7867. {
  7868. result = PASS;
  7869. }
  7870. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7871. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7872. return result;
  7873. }
  7874. //==========================================
  7875. // send confirm routine
  7876. //==========================================
  7877. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7878. {
  7879. mtrace();
  7880. int result = FAIL;
  7881. char message[100]={0};
  7882. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7884. LWS_Send(message);
  7885. result = TRUE;
  7886. return result;
  7887. }
  7888. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7889. {
  7890. mtrace();
  7891. int result = FAIL;
  7892. char message[100]={0};
  7893. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7895. LWS_Send(message);
  7896. result = TRUE;
  7897. return result;
  7898. }
  7899. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7900. {
  7901. mtrace();
  7902. int result = FAIL;
  7903. char message[100]={0};
  7904. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7906. LWS_Send(message);
  7907. result = TRUE;
  7908. return result;
  7909. }
  7910. int sendClearCacheConfirmation(char *uuid,char *payload)
  7911. {
  7912. mtrace();
  7913. int result = FAIL;
  7914. char message[500]={0};
  7915. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7916. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7917. LWS_Send(message);
  7918. return result;
  7919. }
  7920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. char message[500]={0};
  7925. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7926. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7927. LWS_Send(message);
  7928. return result;
  7929. }
  7930. int sendDataTransferConfirmation(char *uuid,char *payload)
  7931. {
  7932. mtrace();
  7933. char statusStr[20]={0};
  7934. char dataStr[10]={0};
  7935. char sstr[20]={0};
  7936. int c = 0;
  7937. char *loc;
  7938. int result = FAIL;
  7939. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7940. /**********************status**************************/
  7941. loc = strstr(payload, "status");
  7942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7943. c = 0;
  7944. while (loc[3+strlen("status")+c] != '\"')
  7945. {
  7946. sstr[c] = loc[3+strlen("status")+c];
  7947. c++;
  7948. }
  7949. sstr[c] = '\0';
  7950. strcpy(statusStr, sstr);
  7951. /**********************data**************************/
  7952. loc = strstr(payload, "data");
  7953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7954. c = 0;
  7955. while (loc[3+strlen("data")+c] != '\"')
  7956. {
  7957. sstr[c] = loc[3+strlen("data")+c];
  7958. c++;
  7959. }
  7960. sstr[c] = '\0';
  7961. strcpy(dataStr, sstr);
  7962. return result;
  7963. }
  7964. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7965. {
  7966. mtrace();
  7967. int result = FAIL;
  7968. char message[1000]={0};
  7969. int CompositeScheduleIndex = 0;
  7970. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7971. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7972. if(nPeriod == 0)
  7973. {
  7974. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7975. {
  7976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7977. ,MESSAGE_TYPE_CALLRESULT
  7978. ,uuid
  7979. ,payload
  7980. ,connectorIdInt);
  7981. }
  7982. else
  7983. {
  7984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7985. ,MESSAGE_TYPE_CALLRESULT
  7986. ,uuid
  7987. ,payload
  7988. ,connectorIdInt
  7989. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7990. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7991. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7992. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7993. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7994. }
  7995. }
  7996. else
  7997. {
  7998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7999. ,MESSAGE_TYPE_CALLRESULT
  8000. ,uuid
  8001. ,payload
  8002. ,connectorIdInt
  8003. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8004. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8005. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8006. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8007. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8008. {
  8009. if (idx_sample == 0)
  8010. {
  8011. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8012. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8013. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8014. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8015. }
  8016. else
  8017. {
  8018. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8019. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8020. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8021. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8022. }
  8023. }
  8024. sprintf(message + strlen(message), "]}}]");
  8025. }
  8026. LWS_Send(message);
  8027. result = TRUE;
  8028. return result;
  8029. }
  8030. int sendGetConfigurationConfirmation(char *uuid)
  8031. {
  8032. mtrace();
  8033. int result = FAIL;
  8034. int MaxKeySupported = 0;
  8035. int sentConfigurationNumber= 0;
  8036. int sentunConfigurationNumber= 0;
  8037. char message[1024*10]={0};
  8038. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8039. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8040. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8041. ,MESSAGE_TYPE_CALLRESULT
  8042. ,uuid );
  8043. //configuration key
  8044. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8045. {
  8046. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8047. {
  8048. if (sentConfigurationNumber == 0)
  8049. {
  8050. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8051. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8052. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8053. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8054. }
  8055. else
  8056. {
  8057. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8058. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8059. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8060. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8061. }
  8062. sentConfigurationNumber = sentConfigurationNumber + 1;
  8063. }
  8064. }
  8065. sprintf(message + strlen(message), "]");
  8066. if(UnknownKeynum != 0)
  8067. {
  8068. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8069. //unkown key
  8070. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8071. {
  8072. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8073. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8074. if(sentunConfigurationNumber == 0)
  8075. {
  8076. sprintf(message + strlen(message), "\"%s\""
  8077. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8078. }
  8079. else
  8080. {
  8081. sprintf(message + strlen(message), ",\"%s\""
  8082. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8083. }
  8084. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8085. }
  8086. sprintf(message + strlen(message), "]");
  8087. }
  8088. sprintf(message + strlen(message), "}]");
  8089. LWS_Send(message);
  8090. return result;
  8091. }
  8092. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8093. {
  8094. mtrace();
  8095. int result = FAIL;
  8096. char message[400]={0};
  8097. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8098. if(strcmp(payload,"")==0)
  8099. {
  8100. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8101. }
  8102. else
  8103. {
  8104. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8105. }
  8106. LWS_Send(message);
  8107. result = TRUE;
  8108. return result;
  8109. }
  8110. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8111. {
  8112. mtrace();
  8113. int result = FAIL;
  8114. char message[80]={0};
  8115. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8116. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8117. LWS_Send(message);
  8118. result = TRUE;
  8119. return result;
  8120. }
  8121. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8122. {
  8123. mtrace();
  8124. int result = FAIL;
  8125. char message[80]={0};
  8126. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8127. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8128. LWS_Send(message);
  8129. result = TRUE;
  8130. return result;
  8131. }
  8132. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8133. {
  8134. mtrace();
  8135. int result = FAIL;
  8136. char message[80]={0};
  8137. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8139. LWS_Send(message);
  8140. result = TRUE;
  8141. return result;
  8142. }
  8143. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8144. {
  8145. mtrace();
  8146. int result = FAIL;
  8147. char message[80]={0};
  8148. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8149. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8150. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8151. LWS_Send(message);
  8152. result = TRUE;
  8153. return result;
  8154. }
  8155. int sendResetConfirmation(char *uuid,char *payload)
  8156. {
  8157. mtrace();
  8158. int result = FAIL;
  8159. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8160. char message[80]={0};
  8161. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8162. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8163. LWS_Send(message);
  8164. result = TRUE;
  8165. return result;
  8166. }
  8167. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8168. {
  8169. mtrace();
  8170. int result = FAIL;
  8171. char message[500]={0};
  8172. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8173. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8174. LWS_Send(message);
  8175. result = TRUE;
  8176. return result;
  8177. }
  8178. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8179. {
  8180. mtrace();
  8181. int result = FAIL;
  8182. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8183. char message[80]={0};
  8184. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8185. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8186. LWS_Send(message);
  8187. result = TRUE;
  8188. return result;
  8189. }
  8190. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8191. {
  8192. mtrace();
  8193. int result = FAIL;
  8194. char message[80]={0};
  8195. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8196. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8197. LWS_Send(message);
  8198. result = TRUE;
  8199. return result;
  8200. }
  8201. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8202. {
  8203. mtrace();
  8204. int result = FAIL;
  8205. char message[80]={0};
  8206. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8207. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8208. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8209. LWS_Send(message);
  8210. result = TRUE;
  8211. return result;
  8212. }
  8213. int sendUpdateFirmwareConfirmation(char *uuid)
  8214. {
  8215. mtrace();
  8216. int result = FAIL;
  8217. char message[60]={0};
  8218. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8219. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8220. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8221. LWS_Send(message);
  8222. result = TRUE;
  8223. return result;
  8224. }
  8225. int sendCertificateSignedConfirmation(char *uuid)
  8226. {
  8227. mtrace();
  8228. int result = PASS;
  8229. char message[4096]={0};
  8230. json_object *CertificateSigned = json_object_new_object();
  8231. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8232. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8233. sprintf(message,"[%d,\"%s\",%s]"
  8234. ,MESSAGE_TYPE_CALLRESULT
  8235. ,uuid
  8236. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8237. json_object_put(CertificateSigned);
  8238. LWS_Send(message);
  8239. return result;
  8240. }
  8241. int sendDeleteCertificateConfirmation(char *uuid)
  8242. {
  8243. mtrace();
  8244. int result = PASS;
  8245. char message[4096]={0};
  8246. json_object *DeleteCertificate = json_object_new_object();
  8247. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8248. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8249. sprintf(message,"[%d,\"%s\",%s]"
  8250. ,MESSAGE_TYPE_CALLRESULT
  8251. ,uuid
  8252. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8253. json_object_put(DeleteCertificate);
  8254. LWS_Send(message);
  8255. return result;
  8256. }
  8257. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8258. {
  8259. mtrace();
  8260. int result = PASS;
  8261. char message[4096]={0};
  8262. json_object *ExtendedTriggerMessage = json_object_new_object();
  8263. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8264. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8265. sprintf(message,"[%d,\"%s\",%s]"
  8266. ,MESSAGE_TYPE_CALLRESULT
  8267. ,uuid
  8268. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8269. json_object_put(ExtendedTriggerMessage);
  8270. LWS_Send(message);
  8271. return result;
  8272. }
  8273. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8274. {
  8275. mtrace();
  8276. int result = PASS;
  8277. char message[4096]={0};
  8278. json_object *GetInstalledCertificateIds = json_object_new_object();
  8279. json_object *certificateHashDataDatas = json_object_new_array();
  8280. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8281. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8282. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8283. {
  8284. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8285. {
  8286. json_object *certificateHashData = json_object_new_object();
  8287. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8288. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8289. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8290. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8291. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8292. }
  8293. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8294. }
  8295. else
  8296. {
  8297. json_object_put(certificateHashDataDatas);
  8298. }
  8299. sprintf(message,"[%d,\"%s\",%s]"
  8300. ,MESSAGE_TYPE_CALLRESULT
  8301. ,uuid
  8302. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8303. json_object_put(GetInstalledCertificateIds);
  8304. LWS_Send(message);
  8305. return result;
  8306. }
  8307. int sendGetLogConfirmation(char *uuid)
  8308. {
  8309. mtrace();
  8310. int result = PASS;
  8311. char message[4096]={0};
  8312. json_object *GetLog = json_object_new_object();
  8313. DEBUG_INFO("sendGetLogConfirmation...\n");
  8314. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8315. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8316. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8317. sprintf(message,"[%d,\"%s\",%s]"
  8318. ,MESSAGE_TYPE_CALLRESULT
  8319. ,uuid
  8320. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8321. json_object_put(GetLog);
  8322. LWS_Send(message);
  8323. return result;
  8324. }
  8325. int sendInstallCertificateConfirmation(char *uuid)
  8326. {
  8327. mtrace();
  8328. int result = PASS;
  8329. char message[4096]={0};
  8330. json_object *InstallCertificate = json_object_new_object();
  8331. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8332. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8333. sprintf(message,"[%d,\"%s\",%s]"
  8334. ,MESSAGE_TYPE_CALLRESULT
  8335. ,uuid
  8336. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8337. json_object_put(InstallCertificate);
  8338. LWS_Send(message);
  8339. return result;
  8340. }
  8341. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8342. {
  8343. mtrace();
  8344. int result = PASS;
  8345. char message[4096]={0};
  8346. json_object *SignedUpdateFirmware = json_object_new_object();
  8347. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8348. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8349. sprintf(message,"[%d,\"%s\",%s]"
  8350. ,MESSAGE_TYPE_CALLRESULT
  8351. ,uuid
  8352. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8353. json_object_put(SignedUpdateFirmware);
  8354. LWS_Send(message);
  8355. return result;
  8356. }
  8357. int sendUnknownConfirmation(char *uuid)
  8358. {
  8359. mtrace();
  8360. int result = PASS;
  8361. char message[256]={0};
  8362. DEBUG_INFO("sendUnknownConfirmation...\n");
  8363. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8364. LWS_Send(message);
  8365. return result;
  8366. }
  8367. //==========================================
  8368. // Handle server request routine Start
  8369. //==========================================
  8370. int handleCancelReservationRequest(char *uuid, char *payload)
  8371. {
  8372. mtrace();
  8373. int result = FAIL;
  8374. int gunNO = 0;
  8375. int reservationIdInt = -1;
  8376. char comfirmstr[20];
  8377. DEBUG_INFO("handleCancelReservationRequest...\n");
  8378. json_object *CancelReservation;
  8379. CancelReservation = json_tokener_parse(payload);
  8380. if(!is_error(CancelReservation))
  8381. {
  8382. // Required data
  8383. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8384. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8385. }
  8386. json_object_put(CancelReservation);
  8387. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8388. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8389. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8390. if(reservationIdInt != -1)
  8391. {
  8392. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8393. //check Transaction active
  8394. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8396. {
  8397. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8398. {
  8399. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8400. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8401. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8402. {
  8403. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8404. }
  8405. else
  8406. {
  8407. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8408. }
  8409. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8410. goto end;
  8411. }
  8412. }
  8413. for (int index = 0; index < CCS_QUANTITY; index++)
  8414. {
  8415. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8416. {
  8417. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8418. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8419. if(gunType[2] == GUN_TYPE_CCS)
  8420. {
  8421. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8422. }
  8423. else
  8424. {
  8425. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8426. }
  8427. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8428. goto end;
  8429. }
  8430. }
  8431. for (int index = 0; index < GB_QUANTITY; index++)
  8432. {
  8433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8434. {
  8435. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8436. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8437. if(gunType[2] == GUN_TYPE_GBT)
  8438. {
  8439. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8440. }
  8441. else
  8442. {
  8443. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8444. }
  8445. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8446. goto end;
  8447. }
  8448. }
  8449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8450. {
  8451. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8452. {
  8453. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8454. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8455. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8456. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8457. goto end;
  8458. }
  8459. }
  8460. for (int index = 0; index < AC_QUANTITY; index++)
  8461. {
  8462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8463. {
  8464. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8465. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8467. {
  8468. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8469. }
  8470. else
  8471. {
  8472. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8473. }
  8474. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8475. goto end;
  8476. }
  8477. }
  8478. }
  8479. //The reservationId does NOT match the reservationId
  8480. sendCancelReservationConfirmation(uuid, comfirmstr);
  8481. end:
  8482. // Fill in ocpp packet uuid
  8483. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8484. return result;
  8485. }
  8486. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8487. {
  8488. mtrace();
  8489. int result = FAIL;
  8490. int gunIndex = -1;
  8491. char typeStr[16]={0};
  8492. char comfirmstr[20];
  8493. int specificId = FALSE;
  8494. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8495. json_object *ChangeAvailability;
  8496. ChangeAvailability = json_tokener_parse(payload);
  8497. if(!is_error(ChangeAvailability))
  8498. {
  8499. // Required data
  8500. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8501. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8502. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8503. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8504. }
  8505. json_object_put(ChangeAvailability);
  8506. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8507. {
  8508. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8509. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8510. }
  8511. else if(gunIndex == 0)
  8512. {
  8513. for(int i=0; i < gunTotalNumber; i++)
  8514. {
  8515. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8516. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8517. }
  8518. }
  8519. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8521. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8522. {
  8523. specificId = TRUE;
  8524. }
  8525. if(specificId == FALSE)
  8526. goto end;
  8527. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8528. {
  8529. //----------------------gunIndex is 0 ------------------------------------------------//
  8530. if(gunIndex == 0)
  8531. {
  8532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8533. {
  8534. for(int i=0; i < gunTotalNumber; i++)
  8535. {
  8536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8537. {
  8538. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8539. {
  8540. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8541. {
  8542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8543. goto end;
  8544. }
  8545. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8546. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8549. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8550. {
  8551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8552. goto end;
  8553. }
  8554. }
  8555. }//END FOR CHAdeMO_QUANTITY
  8556. for (int index = 0; index < CCS_QUANTITY; index++)
  8557. {
  8558. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8559. {
  8560. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8561. {
  8562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8563. goto end;
  8564. }
  8565. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8566. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8570. {
  8571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8572. goto end;
  8573. }
  8574. }
  8575. }//END FOR CCS_QUANTITY
  8576. for (int index = 0; index < GB_QUANTITY; index++)
  8577. {
  8578. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8579. {
  8580. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8581. {
  8582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8583. goto end;
  8584. }
  8585. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8586. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8590. {
  8591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8592. goto end;
  8593. }
  8594. }
  8595. }// END FOR GB_QUANTITY
  8596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8597. {
  8598. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8599. {
  8600. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8601. {
  8602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8603. goto end;
  8604. }
  8605. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8610. {
  8611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8612. goto end;
  8613. }
  8614. }
  8615. }// END FOR GENERAL_GUN_QUANTITY
  8616. for (int index = 0; index < AC_QUANTITY; index++)
  8617. {
  8618. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8619. {
  8620. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8621. {
  8622. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8623. goto end;
  8624. }
  8625. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8630. {
  8631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8632. goto end;
  8633. }
  8634. }
  8635. }//END FOR AC_QUANTITY
  8636. }// END FOR gunTotalNumber
  8637. }
  8638. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8639. {
  8640. for(int i=0; i < gunTotalNumber; i++)
  8641. {
  8642. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8643. {
  8644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8645. goto end;
  8646. }
  8647. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8652. {
  8653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8654. goto end;
  8655. }
  8656. }
  8657. }
  8658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8659. goto end;
  8660. }
  8661. //----------------------gunIndex is not 0 ------------------------------------------------//
  8662. //check Transaction active
  8663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8664. {
  8665. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8666. {
  8667. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8668. {
  8669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8670. goto end;
  8671. }
  8672. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8673. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8677. {
  8678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8679. goto end;
  8680. }
  8681. else
  8682. {
  8683. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8685. goto end;
  8686. }
  8687. }
  8688. }//END FOR CHAdeMO_QUANTITY
  8689. for (int index = 0; index < CCS_QUANTITY; index++)
  8690. {
  8691. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8692. {
  8693. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8694. {
  8695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8696. goto end;
  8697. }
  8698. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8703. {
  8704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8705. goto end;
  8706. }
  8707. else
  8708. {
  8709. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8710. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8711. goto end;
  8712. }
  8713. }
  8714. }//END FOR CCS_QUANTITY
  8715. for (int index = 0; index < GB_QUANTITY; index++)
  8716. {
  8717. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8718. {
  8719. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8720. {
  8721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8722. goto end;
  8723. }
  8724. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8725. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8729. {
  8730. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8731. goto end;
  8732. }
  8733. else
  8734. {
  8735. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8737. goto end;
  8738. }
  8739. }
  8740. }// END FOR GB_QUANTITY
  8741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8742. {
  8743. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8744. {
  8745. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8746. {
  8747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8748. goto end;
  8749. }
  8750. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8755. {
  8756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8757. goto end;
  8758. }
  8759. else
  8760. {
  8761. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8763. goto end;
  8764. }
  8765. }
  8766. }// END FOR GENERAL_GUN_QUANTITY
  8767. for (int index = 0; index < AC_QUANTITY; index++)
  8768. {
  8769. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8770. {
  8771. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8772. {
  8773. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8774. goto end;
  8775. }
  8776. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8781. {
  8782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8783. goto end;
  8784. }
  8785. else
  8786. {
  8787. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8789. goto end;
  8790. }
  8791. }
  8792. }//END FOR AC_QUANTITY
  8793. }//END FOR AvailabilityTypeStr[Inoperative]
  8794. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8795. {
  8796. //----------------------gunIndex is 0 ------------------------------------------------//
  8797. if(gunIndex == 0)
  8798. {
  8799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8800. {
  8801. for(int i=0; i < gunTotalNumber; i++)
  8802. {
  8803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8804. {
  8805. 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
  8806. {
  8807. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8808. goto end;
  8809. }
  8810. }//END FOR CHAdeMO_QUANTITY
  8811. for (int index = 0; index < CCS_QUANTITY; index++)
  8812. {
  8813. 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
  8814. {
  8815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8816. goto end;
  8817. }
  8818. }//END FOR CCS_QUANTITY
  8819. for (int index = 0; index < GB_QUANTITY; index++)
  8820. {
  8821. 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
  8822. {
  8823. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8825. goto end;
  8826. }
  8827. }// END FOR GB_QUANTITY
  8828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8829. {
  8830. 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
  8831. {
  8832. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8833. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8834. goto end;
  8835. }
  8836. }// END FOR GENERAL_GUN_QUANTITY
  8837. for (int index = 0; index < AC_QUANTITY; index++)
  8838. {
  8839. 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
  8840. {
  8841. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8842. goto end;
  8843. }
  8844. }//END FOR CHAdeMO_QUANTITY
  8845. }// END FOR gunTotalNumber
  8846. }
  8847. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8848. {
  8849. for(int i=0; i < gunTotalNumber; i++)
  8850. {
  8851. for (int index = 0; index < AC_QUANTITY; index++)
  8852. {
  8853. 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
  8854. {
  8855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8856. goto end;
  8857. }
  8858. }//END FOR CHAdeMO_QUANTITY
  8859. } // END FOR gunTotalNumber
  8860. }
  8861. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8862. goto end;
  8863. }
  8864. //----------------------gunIndex is not 0 ------------------------------------------------//
  8865. //check Transaction active
  8866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8867. {
  8868. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8869. {
  8870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8871. goto end;
  8872. }
  8873. }//END FOR CHAdeMO_QUANTITY
  8874. for (int index = 0; index < CCS_QUANTITY; index++)
  8875. {
  8876. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8877. {
  8878. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8879. goto end;
  8880. }
  8881. }//END FOR CCS_QUANTITY
  8882. for (int index = 0; index < GB_QUANTITY; index++)
  8883. {
  8884. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8885. {
  8886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8887. goto end;
  8888. }
  8889. }// END FOR GB_QUANTITY
  8890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8891. {
  8892. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8893. {
  8894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8895. goto end;
  8896. }
  8897. }// END FOR GENERAL_GUN_QUANTITY
  8898. for (int index = 0; index < AC_QUANTITY; index++)
  8899. {
  8900. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8901. {
  8902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8903. goto end;
  8904. }
  8905. }//END FOR AC_QUANTITY
  8906. }//END FOR AvailabilityTypeStr[Operative]
  8907. end:
  8908. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8909. {
  8910. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8911. }
  8912. else
  8913. {
  8914. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8915. }
  8916. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8917. {
  8918. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8919. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8920. }
  8921. else if(gunIndex == 0)
  8922. {
  8923. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8924. {
  8925. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8926. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8927. }
  8928. }
  8929. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8930. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8931. return result;
  8932. }
  8933. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8934. {
  8935. mtrace();
  8936. int valueInvalid = NO;
  8937. int result = FAIL;
  8938. char keystr[40]={0};
  8939. char valuestr[501]={0}; //value should be limited in 500 bytes
  8940. char comfirmstr[20]={0};
  8941. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8942. json_object *ChangeConfiguration;
  8943. ChangeConfiguration = json_tokener_parse(payload);
  8944. if(!is_error(ChangeConfiguration))
  8945. {
  8946. // Required data
  8947. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8948. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8949. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8950. {
  8951. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8952. }
  8953. else
  8954. {
  8955. valueInvalid = YES;
  8956. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8957. }
  8958. }
  8959. json_object_put(ChangeConfiguration);
  8960. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8961. {
  8962. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8963. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8964. }
  8965. else
  8966. {
  8967. int status = setKeyValue(keystr, valuestr);
  8968. switch(status)
  8969. {
  8970. case ConfigurationStatus_Accepted:
  8971. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8972. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8973. StoreConfigurationTable();
  8974. break;
  8975. case RebootRequired:
  8976. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8977. StoreConfigurationTable();
  8978. break;
  8979. case NotSupported:
  8980. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8981. break;
  8982. case ConfigurationStatus_Rejected:
  8983. default:
  8984. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8985. break;
  8986. }
  8987. }
  8988. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8989. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8990. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8991. {
  8992. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8993. SetOcppConnStatus(FALSE);
  8994. }
  8995. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8996. {
  8997. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8998. }
  8999. return result;
  9000. }
  9001. int handleClearCacheRequest(char *uuid, char *payload)
  9002. {
  9003. mtrace();
  9004. int result = FAIL;
  9005. char comfirmstr[20];
  9006. char rmFileCmd[100]={0};
  9007. struct stat stats;
  9008. DEBUG_INFO("handleClearCacheRequest...\n");
  9009. stat("/Storage/OCPP", &stats);
  9010. // Check for directory existence
  9011. if (S_ISDIR(stats.st_mode) == 1)
  9012. {}
  9013. else
  9014. {
  9015. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9016. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9017. system(rmFileCmd);
  9018. }
  9019. if(OCPP_cleanLocalCache())
  9020. {
  9021. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9022. }
  9023. else
  9024. {
  9025. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9026. }
  9027. sendClearCacheConfirmation(uuid, comfirmstr);
  9028. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9029. return result;
  9030. }
  9031. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9032. {
  9033. mtrace();
  9034. int result = FAIL;
  9035. int resultRename;
  9036. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9037. char chargingProfilePurposeStr[26]={0};
  9038. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9039. char tempchargingProfilePurposeStr[26]={0};
  9040. char str[100]={0};
  9041. char fname[200]={0};
  9042. char comfirmstr[20]={0};
  9043. char word[1600]={0};
  9044. int clearflag = FALSE;
  9045. int chargingProfileIdIsNULL = FALSE;
  9046. int connectorIsNULL = FALSE;
  9047. int chargingProfilePurposeIsNULL = FALSE;
  9048. int stackLevelIsNULL = FALSE;
  9049. //int GotoEnd = FALSE;
  9050. FILE *fptr1, *fptr2;
  9051. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9052. int n_chargingProfile=0;
  9053. int isEmptyFile = FALSE;
  9054. char sLineWord[1600]={0};
  9055. char chargingProfiles[10][100]={0};
  9056. int ChargeProfileCount = 0;
  9057. int ch;
  9058. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9059. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9060. json_object *ClearChargingProfile;
  9061. ClearChargingProfile = json_tokener_parse(payload);
  9062. if(!is_error(ClearChargingProfile))
  9063. {
  9064. // Optional data
  9065. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9066. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9067. else
  9068. chargingProfileIdIsNULL = TRUE;
  9069. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9070. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9071. else
  9072. connectorIsNULL = TRUE;
  9073. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9074. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9075. else
  9076. chargingProfilePurposeIsNULL = TRUE;
  9077. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9078. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9079. else
  9080. stackLevelIsNULL = TRUE;
  9081. }
  9082. json_object_put(ClearChargingProfile);
  9083. if(connectorIsNULL == FALSE)
  9084. {
  9085. switch(connectorIdInt)
  9086. {
  9087. case 0:
  9088. if(chargingProfilePurposeIsNULL == TRUE)
  9089. {
  9090. int l = 0;
  9091. strcpy(fname, ChargePointMaxProfile_JSON);
  9092. if((access(fname,F_OK))!=-1)
  9093. {
  9094. strcpy(chargingProfiles[l], fname);
  9095. l = l + 1;
  9096. }
  9097. strcpy(fname, TxDefaultProfile_0_JSON);
  9098. if((access(fname,F_OK))!=-1)
  9099. {
  9100. strcpy(chargingProfiles[l], fname);
  9101. l = l + 1;
  9102. }
  9103. ChargeProfileCount = l;
  9104. }
  9105. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9106. {
  9107. strcpy(fname, ChargePointMaxProfile_JSON);
  9108. if((access(fname,F_OK))!=-1)
  9109. {
  9110. strcpy(chargingProfiles[0], fname);
  9111. ChargeProfileCount = 1;
  9112. }
  9113. }
  9114. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9115. {
  9116. strcpy(fname, TxDefaultProfile_0_JSON);
  9117. if((access(fname,F_OK))!=-1)
  9118. {
  9119. strcpy(chargingProfiles[0], fname);
  9120. ChargeProfileCount = 1;
  9121. }
  9122. }
  9123. break;
  9124. default:
  9125. if(chargingProfilePurposeIsNULL == TRUE)
  9126. {
  9127. int m = 0;
  9128. memset(fname, 0, ARRAY_SIZE(fname));
  9129. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9130. if((access(fname,F_OK))!=-1)
  9131. {
  9132. strcpy(chargingProfiles[m], fname);
  9133. m = m + 1;
  9134. }
  9135. memset(fname, 0, ARRAY_SIZE(fname));
  9136. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9137. if((access(fname,F_OK))!=-1)
  9138. {
  9139. strcpy(chargingProfiles[m], fname);
  9140. m = m + 1;
  9141. }
  9142. ChargeProfileCount = m;
  9143. }
  9144. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9145. {
  9146. //strcpy(fname, TxDefaultProfile_1_JSON);
  9147. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9148. if((access(fname,F_OK))!=-1)
  9149. {
  9150. strcpy(chargingProfiles[0], fname);
  9151. ChargeProfileCount = 1;
  9152. }
  9153. }
  9154. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9155. {
  9156. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9157. if((access(fname,F_OK))!=-1)
  9158. {
  9159. strcpy(chargingProfiles[0], fname);
  9160. ChargeProfileCount = 1;
  9161. }
  9162. //strcpy(fname, TxProfile_1_JSON);
  9163. }
  9164. //strcpy(fname, ChargePointMaxProfile_JSON );
  9165. break;
  9166. }
  9167. }
  9168. else // Check all Charging Profiles
  9169. {
  9170. int i = 0;
  9171. char fnametemp[200]={0};
  9172. ChargeProfileCount = 0;
  9173. //Check ChargePointMaxProfile.json exit
  9174. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9175. {
  9176. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9177. i = i + 1;
  9178. }
  9179. //Check TxDefaultProfile_0.json exit
  9180. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9181. {
  9182. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9183. i = i + 1;
  9184. }
  9185. //Check TxDefaultProfile_%d.json
  9186. for(int j=1; j <= gunTotalNumber; j++)
  9187. {
  9188. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9189. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9190. if((access(fnametemp,F_OK))!=-1)
  9191. {
  9192. strcpy(chargingProfiles[i], fnametemp);
  9193. i = i + 1;
  9194. }
  9195. }
  9196. //Check TxProfile_%d.json
  9197. for(int j=1; j <= gunTotalNumber; j++)
  9198. {
  9199. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9200. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9201. if((access(fnametemp,F_OK))!=-1)
  9202. {
  9203. strcpy(chargingProfiles[i], fnametemp);
  9204. i = i + 1;
  9205. }
  9206. }
  9207. ChargeProfileCount = i;
  9208. }// End connectorIsNULL is TRUE
  9209. if(ChargeProfileCount == 0)
  9210. {
  9211. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9212. goto end;
  9213. }
  9214. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9215. {
  9216. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9217. goto end;
  9218. }
  9219. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9220. {
  9221. memset(str, 0, ARRAY_SIZE(str));
  9222. // clear temp file
  9223. sprintf(str,"rm -f %s",temp);
  9224. system(str);
  9225. for(int k=0; k < ChargeProfileCount; k++)
  9226. {
  9227. memset(str, 0, ARRAY_SIZE(str));
  9228. //clear file in C
  9229. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9230. system(str);
  9231. }
  9232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9233. goto end;
  9234. }
  9235. else if(connectorIsNULL == TRUE)
  9236. {
  9237. for(int k=0; k < ChargeProfileCount; k++)
  9238. {
  9239. fptr1 = fopen(chargingProfiles[k], "r");
  9240. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9241. //Check Charging Profile Count
  9242. while(fscanf(fptr1, "%s", word) != EOF)
  9243. {
  9244. //DEBUG_INFO("word=%s\n",word);
  9245. if(strstr(word, "chargingProfileId")!= NULL)
  9246. {
  9247. //DEBUG_INFO("test chargingProfileId \n");
  9248. n_chargingProfile = n_chargingProfile + 1;
  9249. //DEBUG_INFO("chargingProfileId Found\n");
  9250. }
  9251. }
  9252. rewind(fptr1);
  9253. //search Charging Profile Element
  9254. //int i= 0;
  9255. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9256. {
  9257. json_object *tmpProfilee;
  9258. tmpProfilee = json_tokener_parse(sLineWord);
  9259. if(!is_error(tmpProfilee))
  9260. {
  9261. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9262. {
  9263. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9264. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9265. }
  9266. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9267. {
  9268. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9269. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9270. }
  9271. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9272. {
  9273. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9274. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9275. }
  9276. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9277. {
  9278. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9279. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9280. }
  9281. }
  9282. json_object_put(tmpProfilee);
  9283. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9284. {
  9285. //------- not write to fptr2-------//
  9286. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9287. //clearflag = TRUE;
  9288. }
  9289. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9290. {
  9291. //------- not write to fptr2-------//
  9292. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9293. }
  9294. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9295. {
  9296. //------- not write to fptr2-------//
  9297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9298. }
  9299. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9300. {
  9301. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9302. }
  9303. else
  9304. {
  9305. fprintf(fptr2, sLineWord);//writing data into file
  9306. }
  9307. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9308. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9309. if(clearflag == TRUE)
  9310. {
  9311. fclose(fptr1);
  9312. fclose(fptr2);
  9313. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9314. system(str);
  9315. // clear temp file
  9316. sprintf(str,"rm -f %s",temp);
  9317. system(str);
  9318. }
  9319. else
  9320. {
  9321. fclose(fptr1);
  9322. fclose(fptr2);
  9323. memset(str, 0, ARRAY_SIZE(str));
  9324. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9325. system(str);
  9326. resultRename = rename(temp, chargingProfiles[k]);
  9327. if(resultRename == 0)
  9328. {
  9329. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9330. }
  9331. else
  9332. {
  9333. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9334. }
  9335. if(comfirmstr[0]== 0)
  9336. {
  9337. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9338. }
  9339. //Check chargingProfile is empty file
  9340. /*------ Read the file ----------------*/
  9341. fptr1=fopen(chargingProfiles[k],"r");
  9342. ch=fgetc(fptr1);
  9343. rewind(fptr1);
  9344. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9345. if(ch!=EOF)
  9346. {
  9347. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9348. {
  9349. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9350. if(sLineWord[0]=='\0')
  9351. {
  9352. isEmptyFile = TRUE;
  9353. break;
  9354. }
  9355. else
  9356. {
  9357. isEmptyFile = FALSE;
  9358. break;
  9359. }
  9360. }
  9361. }
  9362. else
  9363. isEmptyFile = TRUE;
  9364. fclose(fptr1);
  9365. if(isEmptyFile == TRUE)
  9366. {
  9367. memset(str, 0, ARRAY_SIZE(str));
  9368. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9369. system(str);
  9370. }
  9371. }
  9372. }// End of while(int k=0; k < ChargePointCount; k++)
  9373. }
  9374. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9375. {
  9376. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9377. for(int k=0; k < ChargeProfileCount; k++)
  9378. {
  9379. fptr1 = fopen(chargingProfiles[k], "r");
  9380. fptr2 = fopen(temp, "w+");
  9381. //Check Charging Profile Count
  9382. while(fscanf(fptr1, "%s", word) != EOF)
  9383. {
  9384. //DEBUG_INFO("word=%s\n",word);
  9385. if(strstr(word, "chargingProfileId")!= NULL)
  9386. {
  9387. n_chargingProfile = n_chargingProfile + 1;
  9388. }
  9389. }
  9390. rewind(fptr1);
  9391. //search Charging Profile Element
  9392. //int i= 0;
  9393. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9394. {
  9395. json_object *tmpProfilee;
  9396. tmpProfilee = json_tokener_parse(sLineWord);
  9397. if(!is_error(tmpProfilee))
  9398. {
  9399. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9400. {
  9401. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9402. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9403. }
  9404. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9405. {
  9406. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9407. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9408. }
  9409. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9410. {
  9411. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9412. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9413. }
  9414. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9415. {
  9416. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9417. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9418. }
  9419. }
  9420. json_object_put(tmpProfilee);
  9421. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9422. {
  9423. //------- not write to fptr2-------//
  9424. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9425. //clearflag = TRUE;
  9426. }
  9427. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9428. {
  9429. //------- not write to fptr2-------//
  9430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9431. }
  9432. else if(stackLevelIsNULL == TRUE)
  9433. {
  9434. //Clear Whole File
  9435. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9436. clearflag = TRUE;
  9437. break;
  9438. }
  9439. else
  9440. {
  9441. fprintf(fptr2, sLineWord);//writing data into file
  9442. }
  9443. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9444. }
  9445. if(clearflag == TRUE)
  9446. {
  9447. fclose(fptr1);
  9448. fclose(fptr2);
  9449. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9450. system(str);
  9451. // clear temp file
  9452. sprintf(str,"rm -f %s",temp);
  9453. system(str);
  9454. }
  9455. else
  9456. {
  9457. fclose(fptr1);
  9458. fclose(fptr2);
  9459. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9460. system(str);
  9461. resultRename = rename(temp, chargingProfiles[k]);
  9462. if(resultRename == 0)
  9463. {
  9464. DEBUG_INFO("File ChargingProfile renamed successfully");
  9465. }
  9466. else
  9467. {
  9468. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9469. }
  9470. if(comfirmstr[0]== 0)
  9471. {
  9472. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9473. }
  9474. //Check chargingProfile is empty file
  9475. /*------ Read the file ----------------*/
  9476. fptr1=fopen(chargingProfiles[k],"r");
  9477. ch=fgetc(fptr1);
  9478. rewind(fptr1);
  9479. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9480. if(ch!=EOF)
  9481. {
  9482. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9483. {
  9484. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9485. if(sLineWord[0]=='\0')
  9486. {
  9487. isEmptyFile = TRUE;
  9488. break;
  9489. }
  9490. else
  9491. {
  9492. isEmptyFile = FALSE;
  9493. break;
  9494. }
  9495. }
  9496. }
  9497. else
  9498. isEmptyFile = TRUE;
  9499. fclose(fptr1);
  9500. if(isEmptyFile == TRUE)
  9501. {
  9502. memset(str, 0, ARRAY_SIZE(str));
  9503. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9504. system(str);
  9505. }
  9506. /*------- End of reading ---------------*/
  9507. }
  9508. } // while(int k=0; k < ChargeProfileCount; k++)
  9509. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9510. end:
  9511. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9512. {
  9513. if(connectorIdInt == 0)
  9514. {
  9515. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9516. {
  9517. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9518. }
  9519. }
  9520. else
  9521. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9522. }
  9523. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9524. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9525. return result;
  9526. }
  9527. void createFirmwareVersionByDataTransfer(void)
  9528. {
  9529. json_object *FirmwareDataTransfer = json_object_new_object();
  9530. // AC & DC model
  9531. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9532. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9533. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9534. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9535. // DC model
  9536. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9537. {
  9538. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9539. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9540. (gunType[3] != GUN_TYPE_UNKNOWN))
  9541. {
  9542. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9543. }
  9544. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9545. {
  9546. // DS DM DW
  9547. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9548. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9549. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9550. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9551. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9552. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9553. }
  9554. else
  9555. {
  9556. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9557. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9558. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9559. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9560. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9561. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9562. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9563. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9564. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9565. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9566. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9567. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9568. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9569. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9570. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9571. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9572. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9573. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9574. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9575. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9576. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9577. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9578. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9579. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9580. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9581. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9582. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9583. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9584. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9585. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9586. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9587. }
  9588. }
  9589. // 4G model
  9590. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9591. {
  9592. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9593. }
  9594. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9595. json_object_put(FirmwareDataTransfer);
  9596. }
  9597. int handleDataTransferRequest(char *uuid, char *payload)
  9598. {
  9599. mtrace();
  9600. json_object *response = json_object_new_object();
  9601. int result = FAIL;
  9602. char tempvendorId[255]={0};
  9603. char tempmessageId[50]={0};
  9604. char tempdata[1024]={0};
  9605. char message[2048]={0};
  9606. DEBUG_INFO("handleDataTransferRequest...\n");
  9607. if((uuid != NULL) && (payload != NULL))
  9608. {
  9609. json_object *DataTransfer;
  9610. DataTransfer = json_tokener_parse(payload);
  9611. if(!is_error(DataTransfer))
  9612. {
  9613. // Required data
  9614. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9615. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9616. // Optional data
  9617. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9618. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9619. if(json_object_object_get(DataTransfer, "data") != NULL)
  9620. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9621. result = PASS;
  9622. }
  9623. json_object_put(DataTransfer);
  9624. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9625. {
  9626. // Send all moudle firmware version on EVSE
  9627. createFirmwareVersionByDataTransfer();
  9628. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9629. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9631. json_object_put(response);
  9632. }
  9633. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9634. {
  9635. system("/usr/bin/run_tmate_restart.sh &");
  9636. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9637. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9638. json_object_put(response);
  9639. }
  9640. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9641. {
  9642. json_object *data;
  9643. data = json_tokener_parse(tempdata);
  9644. if(!is_error(data))
  9645. {
  9646. 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))
  9647. {
  9648. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9649. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9650. if(json_object_object_get(data, "SOC") != NULL)
  9651. {
  9652. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9653. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9654. }
  9655. if(json_object_object_get(data, "Energy") != NULL)
  9656. {
  9657. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9658. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9659. }
  9660. if(json_object_object_get(data, "Duration") != NULL)
  9661. {
  9662. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9663. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9664. }
  9665. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9666. }
  9667. else
  9668. {
  9669. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9670. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9671. }
  9672. }
  9673. else
  9674. {
  9675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9677. }
  9678. json_object_put(data);
  9679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9680. json_object_put(response);
  9681. }
  9682. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9683. {
  9684. json_object *data;
  9685. data = json_tokener_parse(tempdata);
  9686. if(!is_error(data))
  9687. {
  9688. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9689. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9690. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9691. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9692. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9693. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9694. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9695. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9696. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9697. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9698. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9699. }
  9700. else
  9701. {
  9702. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9703. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9704. }
  9705. json_object_put(data);
  9706. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9707. json_object_put(response);
  9708. }
  9709. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9710. {
  9711. json_object *data;
  9712. data = json_tokener_parse(tempdata);
  9713. if(!is_error(data))
  9714. {
  9715. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9716. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9717. if(json_object_object_get(data, "idToken") != NULL)
  9718. {
  9719. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9720. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9721. }
  9722. else
  9723. {
  9724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9725. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9726. }
  9727. if(json_object_object_get(data, "price") != NULL) //v1.0
  9728. {
  9729. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9730. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9731. }
  9732. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9733. {
  9734. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9735. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9736. }
  9737. else
  9738. {
  9739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9740. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9741. }
  9742. }
  9743. else
  9744. {
  9745. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9746. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9747. }
  9748. json_object_put(data);
  9749. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9750. json_object_put(response);
  9751. }
  9752. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9753. {
  9754. json_object *data;
  9755. data = json_tokener_parse(tempdata);
  9756. if(!is_error(data))
  9757. {
  9758. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9759. if(json_object_object_get(data, "txId") != NULL)
  9760. {
  9761. // California pricing V1.0
  9762. DEBUG_INFO("California pricing V1.0\n");
  9763. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9764. sprintf((char*)dmsVersion, "1.0");
  9765. for(int idx = 0;idx<gunTotalNumber;idx++)
  9766. {
  9767. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9768. {
  9769. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9770. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9771. if(json_object_object_get(data, "description") != NULL)
  9772. {
  9773. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9774. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9780. }
  9781. }
  9782. }
  9783. }
  9784. else if(json_object_object_get(data, "transactionId") != NULL)
  9785. {
  9786. // California pricing V2.0
  9787. DEBUG_INFO("California pricing V2.0\n");
  9788. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9789. sprintf((char*)dmsVersion, "2.0");
  9790. for(int idx=0;idx<gunTotalNumber;idx++)
  9791. {
  9792. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9793. {
  9794. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9795. if(json_object_object_get(data, "timestamp") != NULL)
  9796. {
  9797. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9798. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9799. }
  9800. else
  9801. {
  9802. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9803. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9804. }
  9805. if(json_object_object_get(data, "meterValue") != NULL)
  9806. {
  9807. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9808. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9809. }
  9810. else
  9811. {
  9812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9813. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9814. }
  9815. if(json_object_object_get(data, "cost") != NULL)
  9816. {
  9817. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9818. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9819. }
  9820. else
  9821. {
  9822. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9823. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9824. }
  9825. if(json_object_object_get(data, "state") != NULL)
  9826. {
  9827. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9828. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9829. }
  9830. else
  9831. {
  9832. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9833. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9834. }
  9835. if(json_object_object_get(data, "chargingPrice") != NULL)
  9836. {
  9837. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9838. {
  9839. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9840. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9841. }
  9842. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9843. {
  9844. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9845. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9846. }
  9847. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9848. {
  9849. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9850. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9851. }
  9852. }
  9853. else
  9854. {
  9855. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9856. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9857. }
  9858. if(json_object_object_get(data, "idlePrice") != NULL)
  9859. {
  9860. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9861. {
  9862. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9863. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9864. }
  9865. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9866. {
  9867. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9868. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9869. }
  9870. }
  9871. if(json_object_object_get(data, "nextPeriod") != NULL)
  9872. {
  9873. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9874. {
  9875. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9876. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9877. }
  9878. else
  9879. {
  9880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9881. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9882. }
  9883. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9884. {
  9885. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9886. {
  9887. 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")));
  9888. 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"));
  9889. }
  9890. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9891. {
  9892. 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")));
  9893. 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"));
  9894. }
  9895. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9896. {
  9897. 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")));
  9898. 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"));
  9899. }
  9900. }
  9901. else
  9902. {
  9903. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9904. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9905. }
  9906. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9907. {
  9908. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9909. {
  9910. 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")));
  9911. 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"));
  9912. }
  9913. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9914. {
  9915. 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")));
  9916. 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"));
  9917. }
  9918. }
  9919. }
  9920. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9921. {
  9922. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9923. {
  9924. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9925. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9926. }
  9927. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9928. {
  9929. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9930. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9931. }
  9932. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9933. {
  9934. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9935. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9936. }
  9937. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9938. {
  9939. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9940. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9941. }
  9942. }
  9943. }
  9944. }
  9945. }
  9946. else
  9947. {
  9948. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9949. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9950. }
  9951. }
  9952. else
  9953. {
  9954. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9955. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9956. }
  9957. json_object_put(data);
  9958. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9959. json_object_put(response);
  9960. }
  9961. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9962. {
  9963. json_object *data;
  9964. data = json_tokener_parse(tempdata);
  9965. if(!is_error(data))
  9966. {
  9967. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9968. if(json_object_object_get(data, "txId") != NULL)
  9969. {
  9970. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9971. for(int idx = 0;idx<gunTotalNumber;idx++)
  9972. {
  9973. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9974. {
  9975. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9976. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9977. if(json_object_object_get(data, "description") != NULL)
  9978. {
  9979. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9980. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9981. }
  9982. else
  9983. {
  9984. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9985. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9986. }
  9987. }
  9988. }
  9989. }
  9990. else if(json_object_object_get(data, "transactionId") != NULL)
  9991. {
  9992. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9993. for(int idx = 0;idx<gunTotalNumber;idx++)
  9994. {
  9995. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9996. {
  9997. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9998. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9999. if(json_object_object_get(data, "cost") != NULL)
  10000. {
  10001. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10002. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10003. }
  10004. else
  10005. {
  10006. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10007. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10008. }
  10009. if(json_object_object_get(data, "priceText") != NULL)
  10010. {
  10011. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10012. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10013. }
  10014. else
  10015. {
  10016. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10017. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10018. }
  10019. if(json_object_object_get(data, "qrCodeText") != NULL)
  10020. {
  10021. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10022. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10023. }
  10024. }
  10025. }
  10026. }
  10027. else
  10028. {
  10029. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10030. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10031. }
  10032. }
  10033. else
  10034. {
  10035. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10036. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10037. }
  10038. json_object_put(data);
  10039. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10040. json_object_put(response);
  10041. }
  10042. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10043. {
  10044. json_object *data;
  10045. data = json_tokener_parse(tempdata);
  10046. if(!is_error(data))
  10047. {
  10048. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10049. if(json_object_object_get(data, "Content_Type") != NULL)
  10050. {
  10051. 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))
  10052. {
  10053. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10054. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10055. {
  10056. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10057. }
  10058. }
  10059. else
  10060. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10061. }
  10062. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10063. }
  10064. else
  10065. {
  10066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10068. }
  10069. json_object_put(data);
  10070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10071. json_object_put(response);
  10072. }
  10073. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10074. {
  10075. json_object *data;
  10076. data = json_tokener_parse(tempdata);
  10077. if(!is_error(data))
  10078. {
  10079. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10080. if(json_object_object_get(data, "ConnectorId") != NULL)
  10081. {
  10082. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10083. }
  10084. if(json_object_object_get(data, "SerialNo") != NULL)
  10085. {
  10086. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10087. }
  10088. if(json_object_object_get(data, "Page_Index") != NULL)
  10089. {
  10090. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10091. }
  10092. if(json_object_object_get(data, "Duration") != NULL)
  10093. {
  10094. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10095. }
  10096. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10097. }
  10098. else
  10099. {
  10100. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10101. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10102. }
  10103. json_object_put(data);
  10104. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10105. json_object_put(response);
  10106. }
  10107. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10108. {
  10109. json_object *data;
  10110. data = json_tokener_parse(tempdata);
  10111. if(!is_error(data))
  10112. {
  10113. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10114. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10115. {
  10116. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10117. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10118. else
  10119. {
  10120. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10121. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10122. }
  10123. }
  10124. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10125. {
  10126. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10127. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10128. else
  10129. {
  10130. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10131. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10132. }
  10133. }
  10134. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10135. {
  10136. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10137. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10138. else
  10139. {
  10140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10141. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10142. }
  10143. }
  10144. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10145. {
  10146. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10147. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10148. else
  10149. {
  10150. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10151. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10152. }
  10153. }
  10154. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10155. {
  10156. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10157. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10158. else
  10159. {
  10160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10161. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10162. }
  10163. }
  10164. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10165. {
  10166. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10167. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10168. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10169. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10170. else
  10171. {
  10172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10173. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10174. }
  10175. }
  10176. if(json_object_object_get(data, "isAuthentication") != NULL)
  10177. {
  10178. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10179. {
  10180. case 0:
  10181. case 1:
  10182. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10183. break;
  10184. default:
  10185. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10186. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10187. break;
  10188. }
  10189. }
  10190. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10191. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10192. }
  10193. else
  10194. {
  10195. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10196. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10197. }
  10198. json_object_put(data);
  10199. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10200. json_object_put(response);
  10201. }
  10202. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10203. {
  10204. json_object *data;
  10205. data = json_tokener_parse(tempdata);
  10206. if(!is_error(data))
  10207. {
  10208. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10209. {
  10210. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10211. {
  10212. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10213. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10214. }
  10215. else
  10216. {
  10217. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10218. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10219. }
  10220. }
  10221. else
  10222. {
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. }
  10226. }
  10227. else
  10228. {
  10229. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10230. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10231. }
  10232. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10233. json_object_put(response);
  10234. }
  10235. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10236. {
  10237. json_object *data;
  10238. data = json_tokener_parse(tempdata);
  10239. if(!is_error(data))
  10240. {
  10241. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10242. if(json_object_object_get(data, "stationName") != NULL)
  10243. {
  10244. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10245. }
  10246. else
  10247. {
  10248. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10249. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10250. }
  10251. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10252. {
  10253. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10254. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10255. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10256. }
  10257. }
  10258. else
  10259. {
  10260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10261. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10262. }
  10263. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10264. json_object_put(response);
  10265. }
  10266. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10267. {
  10268. json_object *data;
  10269. data = json_tokener_parse(tempdata);
  10270. if(!is_error(data))
  10271. {
  10272. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10273. if(json_object_object_get(data, "weatherId") != NULL)
  10274. {
  10275. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10276. }
  10277. else
  10278. {
  10279. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10280. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10281. }
  10282. if(json_object_object_get(data, "Temperature") != NULL)
  10283. {
  10284. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10285. }
  10286. else
  10287. {
  10288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10289. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10290. }
  10291. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10292. {
  10293. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10294. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10295. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10296. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10297. );
  10298. }
  10299. }
  10300. else
  10301. {
  10302. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10303. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10304. }
  10305. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10306. json_object_put(response);
  10307. }
  10308. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10309. {
  10310. json_object *data;
  10311. data = json_tokener_parse(tempdata);
  10312. if(!is_error(data))
  10313. {
  10314. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10315. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10316. {
  10317. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10318. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10319. }
  10320. else
  10321. {
  10322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10323. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10324. }
  10325. }
  10326. else
  10327. {
  10328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10329. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10330. }
  10331. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10332. json_object_put(response);
  10333. }
  10334. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10335. {
  10336. json_object *data;
  10337. data = json_tokener_parse(tempdata);
  10338. if(!is_error(data))
  10339. {
  10340. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10341. {
  10342. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10343. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10344. if(gun_index < gunTotalNumber)
  10345. {
  10346. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10347. {
  10348. json_object *responsedata = json_object_new_object();
  10349. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10350. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10351. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10352. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10353. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10354. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10355. }
  10356. else
  10357. {
  10358. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10359. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10360. }
  10361. }
  10362. else
  10363. {
  10364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10365. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10366. }
  10367. }
  10368. else
  10369. {
  10370. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10371. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10372. }
  10373. }
  10374. else
  10375. {
  10376. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10377. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10378. }
  10379. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10380. json_object_put(response);
  10381. }
  10382. else
  10383. {
  10384. // Can not find valid message id
  10385. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10386. }
  10387. }
  10388. else
  10389. {
  10390. // Payload is null
  10391. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10392. }
  10393. LWS_Send(message);
  10394. return result;
  10395. }
  10396. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10397. {
  10398. mtrace();
  10399. int result = FAIL;
  10400. int connectorIdInt, durationInt;
  10401. char chargingRateUnitStr[4]={0};
  10402. char comfirmstr[20];
  10403. int confirmPeriods = 0;
  10404. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10405. json_object *GetCompositeSchedule;
  10406. GetCompositeSchedule = json_tokener_parse(payload);
  10407. if(!is_error(GetCompositeSchedule))
  10408. {
  10409. // Required data
  10410. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10411. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10412. else
  10413. connectorIdInt = -1;
  10414. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10415. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10416. else
  10417. durationInt = 86400;
  10418. // Optional data
  10419. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10420. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10421. }
  10422. json_object_put(GetCompositeSchedule);
  10423. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10424. if((connectorIdInt == 0) ||
  10425. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10426. {
  10427. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10428. struct StructChargingProfile tmpProfile[1];
  10429. if(strstr(chargingRateUnitStr, "W") != NULL)
  10430. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10431. else
  10432. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10433. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10434. {
  10435. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10436. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10437. }
  10438. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10439. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10440. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10441. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10442. {
  10443. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10444. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10445. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10446. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10447. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10448. {
  10449. confirmPeriods = idx;
  10450. break;
  10451. }
  10452. }
  10453. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10454. {
  10455. confirmPeriods += 1;
  10456. }
  10457. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10458. }
  10459. else
  10460. {
  10461. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10462. }
  10463. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10464. return result;
  10465. }
  10466. int handleGetConfigurationRequest(char *uuid, char *payload)
  10467. {
  10468. mtrace();
  10469. int result = FAIL;
  10470. int MaxKeySupported = 0;
  10471. int n_keys = 0;
  10472. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10473. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10474. json_object *GetConfiguration;
  10475. GetConfiguration = json_tokener_parse(payload);
  10476. if(!is_error(GetConfiguration))
  10477. {
  10478. // Optional data
  10479. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10480. {
  10481. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10482. {
  10483. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10484. n_keys = idx + 1;
  10485. }
  10486. }
  10487. }
  10488. json_object_put(GetConfiguration);
  10489. UnknownKeynum = 0;
  10490. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10491. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10492. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10493. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10494. if(n_keys != 0)
  10495. {
  10496. for(int i=0;i<n_keys;i++)
  10497. {
  10498. getKeyValue(requestKey[i]);
  10499. }
  10500. }
  10501. else
  10502. {
  10503. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10504. getKeyValue("");
  10505. }
  10506. processUnkownKey();
  10507. sendGetConfigurationConfirmation(uuid);
  10508. return result;
  10509. }
  10510. static char fnamePlusPath[100]={0};
  10511. static char fnamePWithNoPath[60]={0};
  10512. void checkUploadLog(void)
  10513. {
  10514. FILE *fp;
  10515. /* Open the command for reading. */
  10516. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10517. if (fp == NULL) {
  10518. DEBUG_WARN("Failed to run command\n" );
  10519. exit(1);
  10520. }
  10521. int ftppathlen = 0;
  10522. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10523. int i = 0;
  10524. /* Read the output a line at a time - output it. */
  10525. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10526. if(i==0)
  10527. {
  10528. ftppathlen = strlen(fnamePlusPath);
  10529. DEBUG_INFO("%s\n", fnamePlusPath);
  10530. fnamePlusPath[ftppathlen]='\0';
  10531. break;
  10532. }
  10533. i= i+1;
  10534. }
  10535. /* close */
  10536. pclose(fp);
  10537. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10538. {
  10539. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10540. {
  10541. fnamePlusPath[k]='\0';
  10542. }
  10543. }
  10544. i=1;
  10545. //char fname[60]={0};
  10546. while(i < ftppathlen)
  10547. {
  10548. int len=ftppathlen-i;
  10549. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10550. {
  10551. DEBUG_INFO("compare '/' all right\n");
  10552. break;
  10553. }
  10554. i=i+1;
  10555. }
  10556. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10557. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10558. fnamePWithNoPath[i+1] = '\0';
  10559. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10560. {
  10561. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10562. {
  10563. fnamePWithNoPath[j]='\0';
  10564. }
  10565. }
  10566. FILE* fp1 = fopen(fnamePlusPath, "r");
  10567. if (fp1)
  10568. {
  10569. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10570. // file exists
  10571. fclose(fp1);
  10572. }
  10573. else
  10574. {
  10575. // file doesn't exist
  10576. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10577. }
  10578. }
  10579. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10580. {
  10581. mtrace();
  10582. int result = FAIL;
  10583. time_t CurrentTime;
  10584. struct tm *tm;
  10585. pthread_t th_Status;
  10586. CurrentTime = time(NULL);
  10587. tm = localtime(&CurrentTime);
  10588. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10589. 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);
  10590. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10591. if(!interLock.isGetDiagnosticGoing)
  10592. {
  10593. interLock.isGetDiagnosticGoing = 1;
  10594. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10595. sleep(1);
  10596. }
  10597. else
  10598. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10599. return result;
  10600. }
  10601. void* GetDiagnosticsProcess(void* data)
  10602. {
  10603. pthread_detach(pthread_self());
  10604. mtrace();
  10605. int retriesInt=0, retryIntervalInt=0;
  10606. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10607. 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};
  10608. int port=0;
  10609. int isSuccess = FALSE;
  10610. char cmdBuf[2048];
  10611. struct tm *tmNow;
  10612. time_t CurrentTime;
  10613. struct tm tmStart;
  10614. struct tm tmStop;
  10615. CurrentTime = time(NULL);
  10616. tmNow=localtime(&CurrentTime);
  10617. uint16_t targetYear, targetMonth;
  10618. json_object *GetDiagnostics;
  10619. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10620. GetDiagnostics = json_tokener_parse(data);
  10621. if(!is_error(GetDiagnostics))
  10622. {
  10623. // Required data
  10624. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10625. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10626. // Optional data
  10627. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10628. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10629. else
  10630. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10631. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10632. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10633. else
  10634. retryIntervalInt = 30;
  10635. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10636. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10637. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10638. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10639. }
  10640. json_object_put(GetDiagnostics);
  10641. // Pack log to compress file
  10642. 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) &&
  10643. (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))
  10644. {
  10645. // Pack system log
  10646. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10647. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10648. targetYear = tmStart.tm_year;
  10649. targetMonth = tmStart.tm_mon;
  10650. do
  10651. {
  10652. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10653. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10654. if(targetMonth+1>=13)
  10655. {
  10656. targetYear += 1;
  10657. targetMonth = 1;
  10658. }
  10659. else
  10660. {
  10661. targetMonth += 1;
  10662. }
  10663. }while((targetYear < (tmNow->tm_year+1900)) ||
  10664. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10665. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10666. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10667. system(cmdBuf);
  10668. // Pack charging & event log
  10669. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10670. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10671. targetYear = tmStart.tm_year;
  10672. targetMonth = tmStart.tm_mon;
  10673. do
  10674. {
  10675. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10676. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10677. if(targetMonth+1>=13)
  10678. {
  10679. targetYear += 1;
  10680. targetMonth = 1;
  10681. }
  10682. else
  10683. {
  10684. targetMonth += 1;
  10685. }
  10686. }while((targetYear < (tmNow->tm_year+1900)) ||
  10687. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10688. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10689. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10690. system(cmdBuf);
  10691. // Combine log file
  10692. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10693. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10694. }
  10695. else
  10696. {
  10697. system("exec /root/logPackTools 'log' 6");
  10698. }
  10699. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10700. system(cmdBuf);
  10701. checkUploadLog();
  10702. //****************location*******************/
  10703. if(strcmp(locationstr,"")==0)
  10704. {
  10705. DEBUG_INFO("location is <Empty>!\n");
  10706. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10707. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10708. goto end;
  10709. }
  10710. memset(protocol, 0, ARRAY_SIZE(protocol));
  10711. memset(user, 0, ARRAY_SIZE(user) );
  10712. memset(password, 0, ARRAY_SIZE(password));
  10713. memset(host, 0, ARRAY_SIZE(host));
  10714. memset(path, 0, ARRAY_SIZE(path));
  10715. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10716. memset(host1, 0, ARRAY_SIZE(host1));
  10717. memset(path1, 0, ARRAY_SIZE(path1));
  10718. /*location: ftp://user:password@host:port/path*/
  10719. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10720. if((access(fnamePlusPath,F_OK))!=-1)
  10721. {
  10722. DEBUG_INFO("fnamePlusPath exist.\n");
  10723. }
  10724. else
  10725. {
  10726. DEBUG_INFO("fnamePlusPath not exist!\n");
  10727. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10728. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10729. goto end;
  10730. }
  10731. if(strchr(locationstr,'@')==NULL)
  10732. {
  10733. sscanf(locationstr,
  10734. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10735. protocol, host, &port, path);
  10736. strcpy(user,"anonymous");
  10737. strcpy(password,"");
  10738. }
  10739. else
  10740. {
  10741. //DEBUG_INFO("pch=%s\n", pch);
  10742. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10743. protocol, user, password, host, &port, path);
  10744. }
  10745. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10746. {
  10747. DEBUG_INFO("protocol is not ftp/http ! \n");
  10748. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10749. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10750. goto end;
  10751. }
  10752. if(strncmp(locationstr,"http", 4) == 0)
  10753. {
  10754. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10755. sprintf(ftppath,"/%s", path);
  10756. do
  10757. {
  10758. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10759. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10760. sleep(3);
  10761. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10762. if(!isSuccess)
  10763. {
  10764. DEBUG_INFO("Diagnostics fail.\n");
  10765. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10766. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10767. sleep(retryIntervalInt);
  10768. }
  10769. else
  10770. {
  10771. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10772. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10773. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10774. }
  10775. retriesInt--;
  10776. }while((isSuccess == 0)&&(retriesInt >= 0));
  10777. }
  10778. else
  10779. {
  10780. sscanf(host,"%[^/]%s",host1, path1);
  10781. if(strlen(path) > 0)
  10782. sprintf(ftppath,"/%s", path);
  10783. else
  10784. sprintf(ftppath,"/%s", path1);
  10785. int ftppathlen=strlen(ftppath);
  10786. int i=1;
  10787. char filenametemp[50];
  10788. while(i < ftppathlen)
  10789. {
  10790. int len=ftppathlen-i;
  10791. if(ftppath[len]== 47) // '/' ascll code: 47
  10792. {
  10793. DEBUG_INFO("find '/' all right\n");
  10794. break;
  10795. }
  10796. i=i+1;
  10797. }
  10798. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10799. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10800. filenametemp[i+1] = 0;
  10801. if(port == 0)
  10802. port = 21;
  10803. do
  10804. {
  10805. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10806. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10807. sleep(3);
  10808. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10809. if(!isSuccess)
  10810. {
  10811. DEBUG_INFO("Diagnostics fail.\n");
  10812. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10813. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10814. sleep(retryIntervalInt);
  10815. }
  10816. else
  10817. {
  10818. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10819. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10820. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10821. }
  10822. retriesInt--;
  10823. }while((!isSuccess)&&(retriesInt >= 0));
  10824. }
  10825. end:
  10826. system("rm -f /mnt/*");
  10827. sleep(5);
  10828. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10829. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10830. interLock.isGetDiagnosticGoing = 0;
  10831. pthread_exit(NULL);
  10832. }
  10833. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10834. {
  10835. mtrace();
  10836. int result = FAIL;
  10837. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10838. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10839. {
  10840. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10841. locallistVersion = -1;
  10842. }
  10843. else
  10844. {
  10845. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10846. locallistVersion = 0;
  10847. OCPP_getListVerion();
  10848. }
  10849. //from db.OCPP_getListVerion
  10850. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10851. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10852. sendGetLocalListVersionConfirmation(uuid,"");
  10853. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10854. return result;
  10855. }
  10856. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10857. {
  10858. mtrace();
  10859. int result = FAIL;
  10860. int connectorIdInt=-1;
  10861. int tempIndex = 0;
  10862. int connectorIdIsNULL, chargingProfileIsNULL;
  10863. char comfirmstr[20]={0};
  10864. char cmdBuf[512];
  10865. json_object *RemoteStartTransaction;
  10866. FILE *fp;
  10867. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10868. if(server_pending == TRUE)
  10869. {
  10870. return 0;
  10871. }
  10872. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10873. RemoteStartTransaction = json_tokener_parse(payload);
  10874. if(!is_error(RemoteStartTransaction))
  10875. {
  10876. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10877. {
  10878. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10879. }
  10880. else
  10881. {
  10882. connectorIdIsNULL = TRUE;
  10883. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10884. {
  10885. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10886. {
  10887. connectorIdIsNULL = FALSE;
  10888. connectorIdInt = (gun_index+1);
  10889. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10890. break;
  10891. }
  10892. }
  10893. }
  10894. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10895. {
  10896. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10897. // Required data
  10898. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10899. // Optional data
  10900. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10901. {
  10902. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10903. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10904. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10905. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10906. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10907. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10908. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10909. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10910. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10911. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10912. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10913. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10914. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10915. {
  10916. 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")));
  10917. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10918. 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"));
  10919. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10920. 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"));
  10921. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10922. 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")));
  10923. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10924. {
  10925. 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++)
  10926. {
  10927. 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"));
  10928. 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"));
  10929. 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)
  10930. 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"));
  10931. }
  10932. }
  10933. }
  10934. }
  10935. else
  10936. {
  10937. chargingProfileIsNULL = TRUE;
  10938. }
  10939. }
  10940. }
  10941. else
  10942. {
  10943. connectorIdIsNULL = TRUE;
  10944. }
  10945. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10946. {
  10947. DEBUG_WARN("Connector id is NULL\n.");
  10948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10949. goto end;
  10950. }
  10951. /*
  10952. enum _SYSTEM_STATUS
  10953. {
  10954. S_BOOTING = 0,
  10955. S_IDLE, = 1
  10956. S_AUTHORIZING, = 2
  10957. S_REASSIGN_CHECK, = 3
  10958. S_REASSIGN, = 4
  10959. S_PRECHARGE, = 5
  10960. S_PREPARING_FOR_EV, = 6
  10961. S_PREPARING_FOR_EVSE, = 7
  10962. S_CHARGING, = 8
  10963. S_TERMINATING, = 9
  10964. S_COMPLETE, = 10
  10965. S_ALARM, = 11
  10966. S_FAULT = 12
  10967. }
  10968. */
  10969. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10970. {
  10971. //check Transaction active
  10972. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10973. {
  10974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10975. {
  10976. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10977. }
  10978. else
  10979. {
  10980. tempIndex = connectorIdInt -1;
  10981. }
  10982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10983. {
  10984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10985. {
  10986. 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))
  10987. {
  10988. //Reserved
  10989. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10990. }
  10991. 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))
  10992. {
  10993. //Reserved
  10994. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10995. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10996. goto end;
  10997. }
  10998. else
  10999. {
  11000. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11001. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11002. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11003. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11004. {
  11005. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  11006. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11007. goto end;
  11008. }
  11009. }//END FOR ELSE
  11010. }
  11011. }// END FOR CHAdeMO_QUANTITY
  11012. }
  11013. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11014. {
  11015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11016. {
  11017. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11018. }
  11019. else
  11020. {
  11021. tempIndex = connectorIdInt -1;
  11022. }
  11023. for (int index = 0; index < CCS_QUANTITY; index++)
  11024. {
  11025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11026. {
  11027. 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))
  11028. {
  11029. //Reserved
  11030. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11031. }
  11032. 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))
  11033. {
  11034. //Reserved
  11035. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11037. goto end;
  11038. }
  11039. else
  11040. {
  11041. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11042. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11043. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11044. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11045. {
  11046. DEBUG_WARN("CCS connector not allow start\n.");
  11047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11048. goto end;
  11049. }
  11050. }// END FOR ELSE
  11051. }
  11052. }// END FOR CCS_QUANTITY
  11053. }
  11054. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11055. {
  11056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11057. {
  11058. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11059. }
  11060. else
  11061. {
  11062. tempIndex = connectorIdInt -1;
  11063. }
  11064. for (int index = 0; index < GB_QUANTITY; index++)
  11065. {
  11066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11067. {
  11068. 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))
  11069. {
  11070. //Reserved
  11071. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11072. }
  11073. 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))
  11074. {
  11075. //Reserved
  11076. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11077. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11078. goto end;
  11079. }
  11080. else
  11081. {
  11082. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11083. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11084. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11085. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11086. {
  11087. DEBUG_WARN("GB connector not allow start\n.");
  11088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11089. goto end;
  11090. }
  11091. }// END FOR ELSE
  11092. }
  11093. } // END FOR GB_QUANTITY
  11094. }
  11095. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11096. {
  11097. tempIndex = connectorIdInt -1;
  11098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11099. {
  11100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11101. {
  11102. 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))
  11103. {
  11104. //Reserved
  11105. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11106. }
  11107. 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))
  11108. {
  11109. //Reserved
  11110. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11112. goto end;
  11113. }
  11114. else
  11115. {
  11116. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11117. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11118. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11119. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11120. {
  11121. DEBUG_WARN("GB connector not allow start\n.");
  11122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11123. goto end;
  11124. }
  11125. }// END FOR ELSE
  11126. }
  11127. } // END FOR GB_QUANTITY
  11128. }
  11129. else
  11130. {
  11131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11132. {
  11133. tempIndex = 2;
  11134. }
  11135. else
  11136. {
  11137. tempIndex = connectorIdInt -1;
  11138. }
  11139. for (int index = 0; index < AC_QUANTITY; index++)
  11140. {
  11141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11142. {
  11143. 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))
  11144. {
  11145. //Reserved
  11146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  11147. }
  11148. 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))
  11149. {
  11150. //Reserved
  11151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  11152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11153. goto end;
  11154. }
  11155. else
  11156. {
  11157. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11158. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11159. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11160. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11161. {
  11162. DEBUG_WARN("AC connector not allow start\n.");
  11163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11164. goto end;
  11165. }
  11166. }//END FOR ELSE
  11167. }
  11168. }// END FOR AC_QUANTITY
  11169. }
  11170. if(chargingProfileIsNULL == FALSE)
  11171. {
  11172. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11173. {
  11174. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11175. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11176. //memset idTag
  11177. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11178. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11179. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11180. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11181. // Save profile to file
  11182. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11183. system(cmdBuf);
  11184. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11185. fp = fopen(cmdBuf, "w");
  11186. 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));
  11187. fclose(fp);
  11188. }
  11189. else
  11190. {
  11191. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11193. }
  11194. }
  11195. else
  11196. {
  11197. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11199. //memset idTag
  11200. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11201. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11202. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11203. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11204. }
  11205. }
  11206. else
  11207. {
  11208. DEBUG_WARN("Connector id over\n.");
  11209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11210. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11211. }
  11212. end:
  11213. json_object_put(RemoteStartTransaction);
  11214. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11215. {
  11216. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11217. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11218. }
  11219. //OCPP send RemoteStartConfirmation by first.
  11220. sendRemoteStartConfirmation(uuid, comfirmstr);
  11221. return result;
  11222. }
  11223. int handleRemoteStartRequest(char *uuid, char *payload)
  11224. {
  11225. mtrace();
  11226. int result = PASS;
  11227. int connectorIdInt=-1;
  11228. int tempIndex = 0;
  11229. char comfirmstr[20]={0};
  11230. char cmdBuf[512];
  11231. json_object *RemoteStartTransaction;
  11232. FILE *fp;
  11233. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11234. if(server_pending == TRUE)
  11235. {
  11236. result = FAIL;
  11237. }
  11238. RemoteStartTransaction = json_tokener_parse(payload);
  11239. if(!is_error(RemoteStartTransaction))
  11240. {
  11241. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11242. {
  11243. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11244. }
  11245. else
  11246. {
  11247. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11248. {
  11249. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11250. {
  11251. connectorIdInt = (gun_index+1);
  11252. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11253. break;
  11254. }
  11255. }
  11256. }
  11257. if(connectorIdInt == 0)
  11258. {
  11259. DEBUG_WARN("Connector id shall not equal 0.\n");
  11260. result = FAIL;
  11261. }
  11262. else if(connectorIdInt == -1)
  11263. {
  11264. DEBUG_INFO("Connector id does not specific.\n");
  11265. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11266. {
  11267. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11268. // Required data
  11269. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11270. // Optional data
  11271. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11272. {
  11273. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11274. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11275. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11276. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11277. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11278. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11279. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11280. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11281. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11282. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11283. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11284. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11285. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11286. {
  11287. 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")));
  11288. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11289. 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"));
  11290. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11291. 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"));
  11292. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11293. 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")));
  11294. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11295. {
  11296. 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++)
  11297. {
  11298. 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"));
  11299. 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"));
  11300. 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)
  11301. 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"));
  11302. }
  11303. }
  11304. }
  11305. }
  11306. else
  11307. {
  11308. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11309. }
  11310. }
  11311. }
  11312. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11313. {
  11314. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11315. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11316. // Required data
  11317. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11318. // Optional data
  11319. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11320. {
  11321. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11322. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11323. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11324. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11325. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11326. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11327. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11328. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11329. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11330. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11331. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11332. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11333. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11334. {
  11335. 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")));
  11336. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11337. 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"));
  11338. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11339. 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"));
  11340. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11341. 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")));
  11342. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11343. {
  11344. 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++)
  11345. {
  11346. 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"));
  11347. 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"));
  11348. 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)
  11349. 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"));
  11350. }
  11351. }
  11352. }
  11353. }
  11354. else
  11355. {
  11356. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11357. }
  11358. }
  11359. else
  11360. {
  11361. DEBUG_WARN("Connector id is over maximun value.\n");
  11362. result = FAIL;
  11363. }
  11364. }
  11365. if(result == PASS)
  11366. {
  11367. if(connectorIdInt > 0)
  11368. {
  11369. //check Transaction active
  11370. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11371. {
  11372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11373. {
  11374. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11375. }
  11376. else
  11377. {
  11378. tempIndex = connectorIdInt -1;
  11379. }
  11380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11381. {
  11382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11383. {
  11384. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11385. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11386. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11387. {
  11388. //Reserved
  11389. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11390. }
  11391. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11392. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11393. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11394. {
  11395. //Reserved
  11396. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11397. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11398. goto end;
  11399. }
  11400. else
  11401. {
  11402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11403. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11404. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11405. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11406. {
  11407. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11408. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11409. goto end;
  11410. }
  11411. }//END FOR ELSE
  11412. }
  11413. }// END FOR CHAdeMO_QUANTITY
  11414. }
  11415. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11416. {
  11417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11418. {
  11419. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11420. }
  11421. else
  11422. {
  11423. tempIndex = connectorIdInt -1;
  11424. }
  11425. for (int index = 0; index < CCS_QUANTITY; index++)
  11426. {
  11427. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11428. {
  11429. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11431. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11432. {
  11433. //Reserved
  11434. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11435. }
  11436. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11437. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11438. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11439. {
  11440. //Reserved
  11441. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11443. goto end;
  11444. }
  11445. else
  11446. {
  11447. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11448. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11449. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11450. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11451. {
  11452. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11454. goto end;
  11455. }
  11456. }// END FOR ELSE
  11457. }
  11458. }// END FOR CCS_QUANTITY
  11459. }
  11460. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11461. {
  11462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11463. {
  11464. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11465. }
  11466. else
  11467. {
  11468. tempIndex = connectorIdInt -1;
  11469. }
  11470. for (int index = 0; index < GB_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11473. {
  11474. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11475. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11476. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11477. {
  11478. //Reserved
  11479. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11480. }
  11481. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11482. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11483. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11484. {
  11485. //Reserved
  11486. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11487. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11488. goto end;
  11489. }
  11490. else
  11491. {
  11492. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11493. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11494. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11495. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11496. {
  11497. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11499. goto end;
  11500. }
  11501. }// END FOR ELSE
  11502. }
  11503. } // END FOR GB_QUANTITY
  11504. }
  11505. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11506. {
  11507. tempIndex = connectorIdInt -1;
  11508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11509. {
  11510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11511. {
  11512. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11513. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11514. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11515. {
  11516. //Reserved
  11517. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11518. }
  11519. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11520. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11521. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11522. {
  11523. //Reserved
  11524. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11526. goto end;
  11527. }
  11528. else
  11529. {
  11530. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11531. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11532. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11533. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11534. {
  11535. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11537. goto end;
  11538. }
  11539. }// END FOR ELSE
  11540. }
  11541. } // END FOR GB_QUANTITY
  11542. }
  11543. else
  11544. {
  11545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11546. {
  11547. tempIndex = 2;
  11548. }
  11549. else
  11550. {
  11551. tempIndex = connectorIdInt -1;
  11552. }
  11553. for (int index = 0; index < AC_QUANTITY; index++)
  11554. {
  11555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11556. {
  11557. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11558. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11559. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11560. {
  11561. //Reserved
  11562. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11563. }
  11564. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11565. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11566. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11567. {
  11568. //Reserved
  11569. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11571. goto end;
  11572. }
  11573. else
  11574. {
  11575. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11576. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11577. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11578. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11579. {
  11580. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11582. goto end;
  11583. }
  11584. }//END FOR ELSE
  11585. }
  11586. }// END FOR AC_QUANTITY
  11587. }
  11588. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11589. {
  11590. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11591. {
  11592. // Save profile to file
  11593. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11594. system(cmdBuf);
  11595. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11596. fp = fopen(cmdBuf, "w");
  11597. 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));
  11598. fclose(fp);
  11599. }
  11600. else
  11601. {
  11602. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11604. goto end;
  11605. }
  11606. }
  11607. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11608. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11609. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11610. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11611. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11612. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11613. }
  11614. else
  11615. {
  11616. uint8_t isHasIdleConnector = FALSE;
  11617. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11618. {
  11619. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11620. {
  11621. isHasIdleConnector = TRUE;
  11622. break;
  11623. }
  11624. }
  11625. if(isHasIdleConnector == TRUE)
  11626. {
  11627. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11628. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11629. {
  11630. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11631. {
  11632. // Save profile to file
  11633. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11634. system(cmdBuf);
  11635. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11636. fp = fopen(cmdBuf, "w");
  11637. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11638. fclose(fp);
  11639. refreshStartTimer(&clientTime.RemoteStartWait);
  11640. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11642. }
  11643. else
  11644. {
  11645. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11647. }
  11648. }
  11649. else
  11650. {
  11651. refreshStartTimer(&clientTime.RemoteStartWait);
  11652. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11653. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11654. }
  11655. }
  11656. else
  11657. {
  11658. DEBUG_INFO("There is not any connector is idle.\n");
  11659. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11660. }
  11661. }
  11662. }
  11663. else
  11664. {
  11665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11666. }
  11667. end:
  11668. json_object_put(RemoteStartTransaction);
  11669. sendRemoteStartConfirmation(uuid, comfirmstr);
  11670. return result;
  11671. }
  11672. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11673. {
  11674. mtrace();
  11675. int result = FAIL;
  11676. int match = FALSE;
  11677. int GunNO = 0;
  11678. int tempIndex = 0;
  11679. int transactionIdInt=0;
  11680. int transactionIdIsNULL= TRUE;
  11681. char comfirmstr[20];
  11682. json_object *RemoteStopTransaction;
  11683. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11684. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11685. if(server_pending == TRUE)
  11686. {
  11687. return 0;
  11688. }
  11689. RemoteStopTransaction = json_tokener_parse(payload);
  11690. if(!is_error(RemoteStopTransaction))
  11691. {
  11692. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11693. {
  11694. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11695. transactionIdIsNULL = FALSE;
  11696. }
  11697. }
  11698. json_object_put(RemoteStopTransaction);
  11699. if(transactionIdIsNULL == FALSE)
  11700. {
  11701. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11702. {
  11703. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11704. {
  11705. //check Transaction active
  11706. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11707. {
  11708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11709. {
  11710. tempIndex = ((gun_index==2) ? 1: 0);
  11711. }
  11712. else
  11713. {
  11714. tempIndex = gun_index;
  11715. }
  11716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11717. {
  11718. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11719. {
  11720. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11721. {
  11722. match = TRUE;
  11723. GunNO = gun_index;
  11724. }
  11725. }
  11726. }// END FOR CHAdeMO_QUANTITY
  11727. }
  11728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11729. {
  11730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11731. {
  11732. tempIndex = ((gun_index==2) ? 1: 0);
  11733. }
  11734. else
  11735. {
  11736. tempIndex = gun_index;
  11737. }
  11738. for (int index = 0; index < CCS_QUANTITY; index++)
  11739. {
  11740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11741. {
  11742. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11743. {
  11744. match = TRUE;
  11745. GunNO = gun_index;
  11746. }
  11747. }
  11748. }// END FOR CCS_QUANTITY
  11749. }
  11750. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11751. {
  11752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11753. {
  11754. tempIndex = ((gun_index==2) ? 1: 0);
  11755. }
  11756. else
  11757. {
  11758. tempIndex = gun_index;
  11759. }
  11760. for (int index = 0; index < GB_QUANTITY; index++)
  11761. {
  11762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11763. {
  11764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11765. {
  11766. match = TRUE;
  11767. GunNO = gun_index;
  11768. }
  11769. }
  11770. }// END FOR GB_QUANTITY
  11771. }
  11772. else if(gunType[gun_index] == GUN_TYPE_DO)
  11773. {
  11774. tempIndex = gun_index;
  11775. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11776. {
  11777. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11778. {
  11779. 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
  11780. {
  11781. match = TRUE;
  11782. GunNO = gun_index;
  11783. }
  11784. }
  11785. }// END FOR GB_QUANTITY
  11786. }
  11787. else
  11788. {
  11789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11790. {
  11791. tempIndex = 2;
  11792. }
  11793. else
  11794. {
  11795. tempIndex = gun_index;
  11796. }
  11797. for (int index = 0; index < AC_QUANTITY; index++)
  11798. {
  11799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11800. {
  11801. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11802. {
  11803. match = TRUE;
  11804. GunNO = gun_index;
  11805. }
  11806. }
  11807. }// END FOR CHAdeMO_QUANTITY
  11808. } // END FOR AC ELSE
  11809. }// CHECK IF ResponseTransactionId == transactionIdInt
  11810. }//END FOR
  11811. if( match == TRUE)
  11812. {
  11813. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11815. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11816. }
  11817. else
  11818. {
  11819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11820. }
  11821. }
  11822. else
  11823. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11824. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11825. return result;
  11826. }
  11827. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11828. {
  11829. mtrace();
  11830. int result = FAIL;
  11831. int connectorIdInt=0, reservationIdInt=0;
  11832. int tempIndex = 0;
  11833. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11834. char comfirmstr[20]={0};
  11835. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11836. int c = 0;
  11837. char *loc;
  11838. //char *ptr;
  11839. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11840. strcpy(sstrtemp, stringtrimspace(payload));
  11841. //***(1)connectorId ****/
  11842. c=0;
  11843. loc = strstr(sstrtemp, "connectorId");
  11844. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11845. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11846. {
  11847. sstr[c] = loc[strlen("connectorId")+2+c];
  11848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11849. c++;
  11850. }
  11851. sstr[c] = '\0';
  11852. connectorIdInt = atoi(sstr);
  11853. //***(2)expiryDate ****/
  11854. loc = strstr(sstrtemp, "expiryDate");
  11855. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11856. c = 0;
  11857. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11858. {
  11859. sstr[c] = loc[3+strlen("expiryDate")+c];
  11860. c++;
  11861. }
  11862. sstr[c] = '\0';
  11863. strcpy(expiryDatestr, sstr);
  11864. //***(3)idTag ****/
  11865. loc = strstr(sstrtemp, "idTag");
  11866. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11867. c = 0;
  11868. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11869. {
  11870. sstr[c] = loc[3+strlen("idTag")+c];
  11871. c++;
  11872. }
  11873. sstr[c] = '\0';
  11874. strcpy(idTagstr, sstr);
  11875. //***(4)parentIdTag ****/
  11876. loc = strstr(sstrtemp, "parentIdTag");
  11877. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11878. c = 0;
  11879. if(loc == NULL)
  11880. {
  11881. strcpy(parentIdTagstr, "");
  11882. }
  11883. else
  11884. {
  11885. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11886. {
  11887. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11888. c++;
  11889. }
  11890. sstr[c] = '\0';
  11891. strcpy(parentIdTagstr, sstr);
  11892. }
  11893. //***(5)reservationId ****/
  11894. c=0;
  11895. loc = strstr(sstrtemp, "reservationId");
  11896. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11897. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11898. {
  11899. sstr[c] = loc[strlen("reservationId")+2+c];
  11900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11901. c++;
  11902. }
  11903. sstr[c] = '\0';
  11904. reservationIdInt = atoi(sstr);
  11905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11906. /*
  11907. enum SYSTEM_STATUS
  11908. {
  11909. SYS_MODE_BOOTING = 0,
  11910. SYS_MODE_IDLE = 1,
  11911. SYS_MODE_AUTHORIZING = 2,
  11912. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11913. SYS_MODE_REASSIGN = 4,
  11914. SYS_MODE_PREPARING = 5,
  11915. SYS_MODE_PREPARE_FOR_EV = 6,
  11916. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11917. SYS_MODE_CHARGING = 8,
  11918. SYS_MODE_TERMINATING = 9,
  11919. SYS_MODE_COMPLETE = 10,
  11920. SYS_MODE_ALARM = 11,
  11921. SYS_MODE_FAULT = 12,
  11922. SYS_MODE_RESERVATION = 13,
  11923. SYS_MODE_BOOKING = 14,
  11924. SYS_MODE_MAINTAIN = 15,
  11925. SYS_MODE_DEBUG = 16,
  11926. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11927. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11928. SYS_MODE_UPDATE = 19
  11929. };
  11930. */
  11931. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11932. {
  11933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11934. goto end;
  11935. }
  11936. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11937. {
  11938. //check Transaction active
  11939. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11940. {
  11941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11942. {
  11943. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11944. }
  11945. else
  11946. {
  11947. tempIndex = connectorIdInt -1;
  11948. }
  11949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11950. {
  11951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11952. {
  11953. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11954. {
  11955. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11956. {
  11957. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11958. {
  11959. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11960. {
  11961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11962. }
  11963. else
  11964. {
  11965. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11967. }
  11968. }
  11969. 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'))
  11970. {
  11971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11972. }
  11973. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11974. {
  11975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11976. }
  11977. else
  11978. {
  11979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11980. }
  11981. }
  11982. 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
  11983. {
  11984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11985. }
  11986. }
  11987. else
  11988. {
  11989. //replace reservation
  11990. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11992. }
  11993. }
  11994. } // END FOR CHAdeMO_QUANTITY
  11995. }
  11996. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11997. {
  11998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11999. {
  12000. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12001. }
  12002. else
  12003. {
  12004. tempIndex = connectorIdInt -1;
  12005. }
  12006. for (int index = 0; index < CCS_QUANTITY; index++)
  12007. {
  12008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12009. {
  12010. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12011. {
  12012. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12013. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12014. {
  12015. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12016. {
  12017. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12018. {
  12019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12020. }
  12021. else
  12022. {
  12023. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12025. }
  12026. }
  12027. 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'))
  12028. {
  12029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12030. }
  12031. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12032. {
  12033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12034. }
  12035. else
  12036. {
  12037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12038. }
  12039. }
  12040. 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
  12041. {
  12042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12043. }
  12044. }
  12045. else
  12046. {
  12047. //replace reservation
  12048. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12050. }
  12051. }
  12052. } // END FOR CCS_QUANTITY
  12053. }
  12054. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12055. {
  12056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12057. {
  12058. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12059. }
  12060. else
  12061. {
  12062. tempIndex = connectorIdInt -1;
  12063. }
  12064. for (int index = 0; index < GB_QUANTITY; index++)
  12065. {
  12066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12067. {
  12068. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12069. {
  12070. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12071. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12072. {
  12073. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12074. {
  12075. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12076. {
  12077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12078. }
  12079. else
  12080. {
  12081. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12083. }
  12084. }
  12085. 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'))
  12086. {
  12087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12088. }
  12089. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12090. {
  12091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12092. }
  12093. else
  12094. {
  12095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12096. }
  12097. }
  12098. 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
  12099. {
  12100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12101. }
  12102. }
  12103. else
  12104. {
  12105. //replace reservation
  12106. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12108. }
  12109. }
  12110. }// END FOR GB_QUANTITY
  12111. }
  12112. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12113. {
  12114. tempIndex = connectorIdInt -1;
  12115. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12116. {
  12117. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12118. {
  12119. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12120. {
  12121. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12122. 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
  12123. {
  12124. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12125. {
  12126. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12127. {
  12128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12129. }
  12130. else
  12131. {
  12132. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12134. }
  12135. }
  12136. 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'))
  12137. {
  12138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12139. }
  12140. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12141. {
  12142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12143. }
  12144. else
  12145. {
  12146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12147. }
  12148. }
  12149. 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
  12150. {
  12151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12152. }
  12153. }
  12154. else
  12155. {
  12156. //replace reservation
  12157. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12159. }
  12160. }
  12161. }// END FOR GB_QUANTITY
  12162. }
  12163. else
  12164. {
  12165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12166. {
  12167. tempIndex = 2;
  12168. }
  12169. else
  12170. {
  12171. tempIndex = (connectorIdInt -1);
  12172. }
  12173. for (int index = 0; index < AC_QUANTITY; index++)
  12174. {
  12175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12176. {
  12177. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12178. {
  12179. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12180. {
  12181. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12182. {
  12183. 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))
  12184. {
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12186. }
  12187. else
  12188. {
  12189. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12191. }
  12192. }
  12193. 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'))
  12194. {
  12195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12196. }
  12197. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12198. {
  12199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12200. }
  12201. else
  12202. {
  12203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12204. }
  12205. }
  12206. 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
  12207. {
  12208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12209. }
  12210. }
  12211. else
  12212. {
  12213. //replace reservation
  12214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12216. }
  12217. }
  12218. } // END FOR AC_QUANTITY
  12219. }
  12220. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12221. }
  12222. else if(connectorIdInt == 0)
  12223. {
  12224. //check Transaction active
  12225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12226. {
  12227. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12228. {
  12229. 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'))
  12230. {
  12231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12232. goto end;
  12233. }
  12234. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12237. goto end;
  12238. }
  12239. 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
  12240. {
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12242. goto end;
  12243. }
  12244. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12245. {
  12246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12247. goto end;
  12248. }
  12249. }
  12250. }// END FOR CHAdeMO_QUANTITY
  12251. for (int index = 0; index < CCS_QUANTITY; index++)
  12252. {
  12253. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12254. {
  12255. 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'))
  12256. {
  12257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12258. goto end;
  12259. }
  12260. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12261. {
  12262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12263. goto end;
  12264. }
  12265. 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
  12266. {
  12267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12268. goto end;
  12269. }
  12270. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12271. {
  12272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12273. goto end;
  12274. }
  12275. }
  12276. } // END FOR CCS_QUANTITY
  12277. for (int index = 0; index < GB_QUANTITY; index++)
  12278. {
  12279. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12280. {
  12281. 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'))
  12282. {
  12283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12284. goto end;
  12285. }
  12286. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12287. {
  12288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12289. goto end;
  12290. }
  12291. 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
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12294. goto end;
  12295. }
  12296. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12297. {
  12298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12299. goto end;
  12300. }
  12301. }
  12302. } // END FOR GB_QUANTITY
  12303. for (int index = 0; index < AC_QUANTITY; index++)
  12304. {
  12305. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12306. {
  12307. 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'))
  12308. {
  12309. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12310. goto end;
  12311. }
  12312. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12313. {
  12314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12315. goto end;
  12316. }
  12317. 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
  12318. {
  12319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12320. goto end;
  12321. }
  12322. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12323. {
  12324. 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))
  12325. {
  12326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12327. goto end;
  12328. }
  12329. }
  12330. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12331. {
  12332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12333. goto end;
  12334. }
  12335. }
  12336. }// END FOR AC_QUANTITY
  12337. //The connectorId is 0
  12338. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12340. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12341. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12342. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12343. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12344. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12345. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12346. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12347. result = TRUE;
  12348. return result;
  12349. }
  12350. else
  12351. {
  12352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12353. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12354. }
  12355. if(strcmp(comfirmstr,"Accepted") == 0)
  12356. {
  12357. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12358. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12359. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12360. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12361. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12362. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12363. result = TRUE;
  12364. return result;
  12365. }
  12366. end:
  12367. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12368. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12369. return result;
  12370. }
  12371. int handleResetRequest(char *uuid, char *payload)
  12372. {
  12373. mtrace();
  12374. int result = FAIL;
  12375. char sstr[10]={0},sstrtemp[30]={ 0 };
  12376. char typestr[10]={0};
  12377. char comfirmstr[20]={0};
  12378. int c = 0;
  12379. char *loc;
  12380. DEBUG_INFO("handleResetRequest...\n");
  12381. strcpy(sstrtemp, stringtrimspace(payload));
  12382. loc = strstr(sstrtemp, "type");
  12383. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12384. c = 0;
  12385. while (loc[3+strlen("type")+c] != '\"')
  12386. {
  12387. sstr[c] = loc[3+strlen("type")+c];
  12388. c++;
  12389. }
  12390. sstr[c] = '\0';
  12391. strcpy(typestr,sstr);
  12392. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12393. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12394. {
  12395. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12396. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12397. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12398. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12399. }
  12400. else
  12401. {
  12402. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12403. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12404. result = PASS;
  12405. }
  12406. sendResetConfirmation(uuid, comfirmstr);
  12407. return result;
  12408. }
  12409. int handleSendLocalListRequest(char *uuid, char *payload)
  12410. {
  12411. mtrace();
  12412. int result = FAIL;
  12413. char comfirmstr[20];
  12414. int checkState_Faulted = FALSE;
  12415. json_object *SendLocalList;
  12416. DEBUG_INFO("handleSendLocalListRequest...\n");
  12417. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12418. {
  12419. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12420. goto end;
  12421. }
  12422. //check Charge Point state
  12423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12424. {
  12425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12426. {
  12427. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12428. }
  12429. }
  12430. for (int index = 0; index < CCS_QUANTITY; index++)
  12431. {
  12432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12433. {
  12434. checkState_Faulted = TRUE; //OCPP Status
  12435. }
  12436. }
  12437. for (int index = 0; index < GB_QUANTITY; index++)
  12438. {
  12439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12440. {
  12441. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12442. }
  12443. }
  12444. //check Charge Point state
  12445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12446. {
  12447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12448. {
  12449. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12450. }
  12451. }
  12452. //check Charge Point state
  12453. for (int index = 0; index < AC_QUANTITY; index++)
  12454. {
  12455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12456. {
  12457. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12458. }
  12459. }
  12460. if(checkState_Faulted == TRUE)
  12461. {
  12462. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12463. goto end;
  12464. }
  12465. // Parsing payload
  12466. SendLocalList = json_tokener_parse(payload);
  12467. if(!is_error(SendLocalList))
  12468. {
  12469. // Required data
  12470. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12471. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12472. // Optional data
  12473. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12474. {
  12475. //Check UpdateType
  12476. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12477. {
  12478. //Local list full update
  12479. DEBUG_INFO("Local list full update.\n");
  12480. locallistVersion = 0;
  12481. OCPP_getListVerion();
  12482. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12483. {
  12484. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12485. goto end;
  12486. }*/
  12487. OCPP_cleanLocalList();
  12488. }
  12489. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12490. {
  12491. //Local list different update
  12492. DEBUG_INFO("Local list different update.\n");
  12493. locallistVersion = 0;
  12494. OCPP_getListVerion();
  12495. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12496. {
  12497. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12498. goto end;
  12499. }
  12500. }
  12501. else
  12502. {
  12503. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12504. goto end;
  12505. }
  12506. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12507. {
  12508. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12509. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12510. goto end;
  12511. }
  12512. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12513. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12514. {
  12515. 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")));
  12516. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12517. {
  12518. 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")));
  12519. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12520. 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")));
  12521. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12522. 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")));
  12523. }
  12524. // Add to db
  12525. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12526. {
  12527. //Local list full update
  12528. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12529. idx,
  12530. ShmOCPP16Data->SendLocalList.ListVersion,
  12531. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12532. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12533. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12534. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12535. // update list
  12536. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12537. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12538. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12539. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12540. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12541. }
  12542. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12543. {
  12544. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12545. idx,
  12546. ShmOCPP16Data->SendLocalList.ListVersion,
  12547. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12548. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12549. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12550. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12551. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12552. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12553. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12554. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12555. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12556. }
  12557. }
  12558. }
  12559. else
  12560. {
  12561. //Check UpdateType
  12562. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12563. {
  12564. //Local list full update
  12565. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12566. OCPP_cleanLocalList();
  12567. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12568. goto end;
  12569. }
  12570. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12571. {
  12572. //Local list different update
  12573. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12574. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12575. goto end;
  12576. }
  12577. }
  12578. result = PASS;
  12579. }
  12580. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12581. end:
  12582. json_object_put(SendLocalList);
  12583. sendSendLocalListConfirmation(uuid, comfirmstr);
  12584. return result;
  12585. }
  12586. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12587. {
  12588. mtrace();
  12589. int result = FAIL;
  12590. struct StructSetChargingProfile SetProfileReq = {0};
  12591. int tempchargingProfileIdInt;
  12592. int tempstackLevelInt;
  12593. int chargingSchedulePeriodCount = 0;
  12594. char comfirmstr[20]={0};
  12595. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12596. char rmFileCmd[128]={0};
  12597. int profileQuantity = 0;
  12598. int replaceableProfileCnt = 0;
  12599. json_object *SetChargingProfile;
  12600. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12601. SetChargingProfile = json_tokener_parse(payload);
  12602. if(!is_error(SetChargingProfile))
  12603. {
  12604. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12605. {
  12606. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12607. }
  12608. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12609. {
  12610. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12611. {
  12612. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12613. }
  12614. else
  12615. {
  12616. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12617. DEBUG_WARN("Cannot find chargingProfileId field.");
  12618. goto end;
  12619. }
  12620. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12621. {
  12622. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12623. }
  12624. else
  12625. {
  12626. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12627. DEBUG_WARN("Cannot find stackLevel field.");
  12628. goto end;
  12629. }
  12630. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12631. {
  12632. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12633. }
  12634. else
  12635. {
  12636. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12637. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12638. goto end;
  12639. }
  12640. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12641. {
  12642. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12643. }
  12644. else
  12645. {
  12646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12647. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12648. goto end;
  12649. }
  12650. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12651. {
  12652. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12653. }
  12654. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12655. {
  12656. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12657. }
  12658. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12659. {
  12660. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12661. }
  12662. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12663. {
  12664. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12665. }
  12666. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12667. {
  12668. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12669. {
  12670. 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")));
  12671. }
  12672. else
  12673. {
  12674. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12675. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12676. goto end;
  12677. }
  12678. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12679. {
  12680. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12681. }
  12682. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12683. {
  12684. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12685. }
  12686. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12687. {
  12688. 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")));
  12689. }
  12690. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12691. {
  12692. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12693. if(chargingSchedulePeriodCount <= 10)
  12694. {
  12695. 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++)
  12696. {
  12697. 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)
  12698. {
  12699. 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"));
  12700. }
  12701. else
  12702. {
  12703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12704. DEBUG_WARN("Cannot find startPeriod field.");
  12705. goto end;
  12706. }
  12707. 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)
  12708. {
  12709. 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"));
  12710. }
  12711. else
  12712. {
  12713. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12714. DEBUG_WARN("Cannot find limit field.");
  12715. goto end;
  12716. }
  12717. 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)
  12718. {
  12719. 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"));
  12720. }
  12721. }
  12722. }
  12723. }
  12724. else
  12725. {
  12726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12727. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12728. goto end;
  12729. }
  12730. }
  12731. else
  12732. {
  12733. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12734. DEBUG_WARN("Cannot find chargingSchedule field.");
  12735. goto end;
  12736. }
  12737. }
  12738. }
  12739. // Profile periods quantity check
  12740. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12741. {
  12742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12743. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12744. goto end;
  12745. }
  12746. // Check invalid limit
  12747. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12748. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12749. {
  12750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12751. {
  12752. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12753. {
  12754. 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)))) ||
  12755. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12756. {
  12757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12758. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12759. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12760. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12761. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12762. goto end;
  12763. }
  12764. }
  12765. }
  12766. else
  12767. {
  12768. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12769. {
  12770. 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) ||
  12771. (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)))
  12772. {
  12773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12774. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12775. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12776. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12777. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12778. goto end;
  12779. }
  12780. }
  12781. }
  12782. }
  12783. // Profile purpose info check
  12784. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12785. {
  12786. FILE *fp;
  12787. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12788. if(SetProfileReq.ConnectorId != 0)
  12789. {
  12790. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12791. DEBUG_WARN("Profile connector id is not 0.\n");
  12792. goto end;
  12793. }
  12794. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12795. if (!fp)
  12796. {
  12797. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12798. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12799. }
  12800. else
  12801. {
  12802. char *line = NULL;
  12803. size_t len = 0;
  12804. while(getline(&line, &len, fp) != -1)
  12805. {
  12806. json_object *obj = NULL;
  12807. obj = json_tokener_parse(line);
  12808. if(is_error(obj))
  12809. {
  12810. DEBUG_ERROR("Parse txProfile from file error.\n");
  12811. }
  12812. else
  12813. {
  12814. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12815. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12816. {
  12817. profileQuantity += 1;
  12818. }
  12819. else
  12820. replaceableProfileCnt += 1;
  12821. }
  12822. }
  12823. }
  12824. fclose(fp);
  12825. }
  12826. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12827. {
  12828. FILE *fp;
  12829. char filename[128]={0};
  12830. int tmpProfileQuantity;
  12831. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12832. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12833. {
  12834. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12835. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12836. goto end;
  12837. }
  12838. if(SetProfileReq.ConnectorId == 0)
  12839. {
  12840. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12841. {
  12842. tmpProfileQuantity = 0;
  12843. memset(filename, 0, ARRAY_SIZE(filename));
  12844. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12845. fp = fopen(filename, "r");
  12846. if (!fp)
  12847. {
  12848. DEBUG_INFO("%s does not create.\n", filename);
  12849. fp = fopen(filename, "w+");
  12850. }
  12851. else
  12852. {
  12853. char *line = NULL;
  12854. size_t len = 0;
  12855. while(getline(&line, &len, fp) != -1)
  12856. {
  12857. json_object *obj = NULL;
  12858. obj = json_tokener_parse(line);
  12859. if(is_error(obj))
  12860. {
  12861. DEBUG_ERROR("Parse txProfile from file error.\n");
  12862. }
  12863. else
  12864. {
  12865. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12866. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12867. {
  12868. tmpProfileQuantity += 1;
  12869. }
  12870. else
  12871. replaceableProfileCnt += 1;
  12872. }
  12873. }
  12874. }
  12875. fclose(fp);
  12876. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12877. }
  12878. }
  12879. else
  12880. {
  12881. memset(filename, 0, ARRAY_SIZE(filename));
  12882. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12883. fp = fopen(filename, "r");
  12884. if (!fp)
  12885. {
  12886. DEBUG_INFO("%s does not create.\n", filename);
  12887. fp = fopen(filename, "w+");
  12888. }
  12889. else
  12890. {
  12891. char *line = NULL;
  12892. size_t len = 0;
  12893. while(getline(&line, &len, fp) != -1)
  12894. {
  12895. json_object *obj = NULL;
  12896. obj = json_tokener_parse(line);
  12897. if(is_error(obj))
  12898. {
  12899. DEBUG_ERROR("Parse txProfile from file error.\n");
  12900. }
  12901. else
  12902. {
  12903. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12904. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12905. {
  12906. profileQuantity += 1;
  12907. }
  12908. else
  12909. replaceableProfileCnt += 1;
  12910. }
  12911. }
  12912. }
  12913. fclose(fp);
  12914. }
  12915. }
  12916. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12917. {
  12918. int isMatchTransactiodId= FALSE;
  12919. FILE *fp;
  12920. char filename[128]={0};
  12921. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12922. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12923. if(SetProfileReq.ConnectorId == 0)
  12924. {
  12925. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12926. DEBUG_WARN("Profile connector id is 0.\n");
  12927. goto end;
  12928. }
  12929. int tempIndex = 0;
  12930. //check Transaction active
  12931. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12932. {
  12933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12934. {
  12935. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12936. }
  12937. else
  12938. {
  12939. tempIndex = SetProfileReq.ConnectorId -1;
  12940. }
  12941. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12942. {
  12943. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12944. {
  12945. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12946. {
  12947. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12948. {
  12949. isMatchTransactiodId = TRUE;
  12950. break;
  12951. }
  12952. }
  12953. }
  12954. }
  12955. }
  12956. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12957. {
  12958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12959. {
  12960. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12961. }
  12962. else
  12963. {
  12964. tempIndex = SetProfileReq.ConnectorId -1;
  12965. }
  12966. for (int index = 0; index < CCS_QUANTITY; index++)
  12967. {
  12968. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12969. {
  12970. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12971. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12972. {
  12973. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12974. {
  12975. isMatchTransactiodId = TRUE;
  12976. break;
  12977. }
  12978. }
  12979. }
  12980. }
  12981. }
  12982. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12983. {
  12984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12985. {
  12986. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12987. }
  12988. else
  12989. {
  12990. tempIndex = SetProfileReq.ConnectorId -1;
  12991. }
  12992. for (int index = 0; index < GB_QUANTITY; index++)
  12993. {
  12994. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12995. {
  12996. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12997. {
  12998. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12999. {
  13000. isMatchTransactiodId = TRUE;
  13001. break;
  13002. }
  13003. }
  13004. }
  13005. }
  13006. }
  13007. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13008. {
  13009. tempIndex = SetProfileReq.ConnectorId -1;
  13010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13011. {
  13012. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13013. {
  13014. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13015. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13016. {
  13017. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13018. {
  13019. isMatchTransactiodId = TRUE;
  13020. break;
  13021. }
  13022. }
  13023. }
  13024. }
  13025. }
  13026. else
  13027. {
  13028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13029. {
  13030. tempIndex = 2;
  13031. }
  13032. else
  13033. {
  13034. tempIndex = (SetProfileReq.ConnectorId -1);
  13035. }
  13036. for (int index = 0; index < AC_QUANTITY; index++)
  13037. {
  13038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13039. {
  13040. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13041. {
  13042. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13043. {
  13044. isMatchTransactiodId = TRUE;
  13045. break;
  13046. }
  13047. }
  13048. }
  13049. }
  13050. }
  13051. //check Transaction active
  13052. if(isMatchTransactiodId == FALSE)
  13053. {
  13054. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13055. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13056. goto end;
  13057. }
  13058. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13059. {
  13060. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13061. DEBUG_WARN("Connector id is over max gun number.\n");
  13062. goto end;
  13063. }
  13064. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13065. fp = fopen(filename, "r");
  13066. if (!fp)
  13067. {
  13068. DEBUG_INFO("%s does not create.\n", filename);
  13069. fp = fopen(filename, "w+");
  13070. }
  13071. else
  13072. {
  13073. char *line = NULL;
  13074. size_t len = 0;
  13075. while(getline(&line, &len, fp) != -1)
  13076. {
  13077. json_object *obj = NULL;
  13078. obj = json_tokener_parse(line);
  13079. if(is_error(obj))
  13080. {
  13081. DEBUG_ERROR("Parse txProfile from file error.\n");
  13082. }
  13083. else
  13084. {
  13085. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13086. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13087. {
  13088. profileQuantity += 1;
  13089. }
  13090. else
  13091. replaceableProfileCnt += 1;
  13092. }
  13093. }
  13094. }
  13095. fclose(fp);
  13096. }
  13097. // Check ChargeProfileMaxStackLevel
  13098. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13099. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13100. {
  13101. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13102. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13103. goto end;
  13104. }
  13105. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13106. {
  13107. FILE *fp;
  13108. char dataLine[4096]={0};
  13109. char fnametemp[128]={0};
  13110. int tmpProfileQuantity;
  13111. //Check ChargePointMaxProfile.json exit
  13112. profileQuantity = 0;
  13113. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13114. {
  13115. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13116. //Check Charging Profile Count
  13117. tmpProfileQuantity = 0;
  13118. while(fscanf(fp, "%s", dataLine) != EOF)
  13119. {
  13120. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13121. {
  13122. profileQuantity += 1;
  13123. tmpProfileQuantity += 1;
  13124. }
  13125. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13126. }
  13127. fclose(fp);
  13128. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13129. }
  13130. //Check TxDefaultProfile_%d.json
  13131. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13132. {
  13133. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13134. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13135. if((access(fnametemp,F_OK))!=-1)
  13136. {
  13137. fp = fopen(fnametemp, "r");
  13138. //Check Charging Profile Count
  13139. tmpProfileQuantity = 0;
  13140. while(fscanf(fp, "%s", dataLine) != EOF)
  13141. {
  13142. //DEBUG_INFO("word=%s\n",word);
  13143. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13144. {
  13145. profileQuantity += 1;
  13146. tmpProfileQuantity += 1;
  13147. }
  13148. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13149. }
  13150. fclose(fp);
  13151. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13152. }
  13153. }
  13154. //Check TxProfile_%d.json
  13155. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13156. {
  13157. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13158. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13159. if((access(fnametemp,F_OK))!=-1)
  13160. {
  13161. fp = fopen(fnametemp, "r");
  13162. //Check Charging Profile Count
  13163. tmpProfileQuantity = 0;
  13164. while(fscanf(fp, "%s", dataLine) != EOF)
  13165. {
  13166. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13167. {
  13168. profileQuantity += 1;
  13169. tmpProfileQuantity += 1;
  13170. }
  13171. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13172. }
  13173. fclose(fp);
  13174. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13175. }
  13176. }
  13177. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13178. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13179. // To check total Profile quantity
  13180. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13181. {
  13182. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13183. {
  13184. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13185. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13186. goto end;
  13187. }
  13188. }
  13189. else
  13190. {
  13191. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13192. {
  13193. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13194. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13195. goto end;
  13196. }
  13197. }
  13198. }
  13199. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13200. //**********************************Write to File********************************************************/
  13201. {
  13202. FILE *infile;
  13203. FILE *outfile;
  13204. char dataLine[4096]={0};
  13205. char filename[128]={0};
  13206. int chkChar=0;
  13207. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13208. {
  13209. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13210. {
  13211. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13212. }
  13213. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13214. {
  13215. if(SetProfileReq.ConnectorId==0)
  13216. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13217. else
  13218. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13219. }
  13220. else
  13221. {
  13222. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13223. }
  13224. infile = fopen (filename, "r");
  13225. outfile = fopen (tempfile, "w");
  13226. chkChar = fgetc(infile);
  13227. rewind(infile);
  13228. if(chkChar == EOF)
  13229. {
  13230. // Profile is empty
  13231. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13232. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13233. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13234. fclose(infile);
  13235. fclose(outfile);
  13236. sprintf(rmFileCmd,"rm -f %s",filename);
  13237. system(rmFileCmd);
  13238. rename(tempfile, filename);
  13239. }
  13240. else
  13241. {
  13242. // Profile is not empty
  13243. int ChargingProfileAdded = FALSE;
  13244. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13245. {
  13246. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13247. json_object *tmpChargingProfile;
  13248. tmpChargingProfile = json_tokener_parse(dataLine);
  13249. if(!is_error(SetChargingProfile))
  13250. {
  13251. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13252. {
  13253. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13254. {
  13255. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13256. }
  13257. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13258. {
  13259. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13260. }
  13261. }
  13262. }
  13263. json_object_put(tmpChargingProfile);
  13264. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13265. {
  13266. if(ChargingProfileAdded == FALSE)
  13267. {
  13268. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13269. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13270. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13271. ChargingProfileAdded = TRUE;
  13272. }
  13273. }
  13274. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13275. {
  13276. if(ChargingProfileAdded == FALSE)
  13277. {
  13278. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13279. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13280. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13281. ChargingProfileAdded = TRUE;
  13282. }
  13283. }
  13284. else
  13285. {
  13286. fprintf(outfile,"%s\n",dataLine);
  13287. if(ChargingProfileAdded == FALSE)
  13288. {
  13289. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13290. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13291. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13292. ChargingProfileAdded = TRUE;
  13293. }
  13294. }
  13295. } // end of while loop
  13296. fclose(infile);
  13297. fclose(outfile);
  13298. sprintf(rmFileCmd,"rm -f %s",filename);
  13299. system(rmFileCmd);
  13300. rename(tempfile, filename);
  13301. }
  13302. }
  13303. sleep(1);
  13304. result = TRUE;
  13305. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13306. }
  13307. end:
  13308. json_object_put(SetChargingProfile);
  13309. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13310. {
  13311. if(SetProfileReq.ConnectorId == 0)
  13312. {
  13313. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13314. {
  13315. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13316. }
  13317. }
  13318. else
  13319. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13320. }
  13321. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13322. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13323. return result;
  13324. }
  13325. int handleTriggerMessageRequest(char *uuid, char *payload)
  13326. {
  13327. mtrace();
  13328. int result = FAIL;
  13329. int connectorIdIsNULL = FALSE;
  13330. int connectorIdInt =0;
  13331. char sstr[40]={0},sstrtemp[100]={ 0 };
  13332. char requestedMessagestr[40]={0};
  13333. char comfirmstr[20]={0};
  13334. int c = 0;
  13335. char *loc;
  13336. DEBUG_INFO("handleTriggerMessageRequest\n");
  13337. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13338. strcpy(sstrtemp, stringtrimspace(payload));
  13339. c = 0;
  13340. loc = strstr(sstrtemp, "requestedMessage");
  13341. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13342. {
  13343. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13344. c++;
  13345. }
  13346. sstr[c] = '\0';
  13347. strcpy(requestedMessagestr, sstr);
  13348. c = 0;
  13349. loc = strstr(sstrtemp, "connectorId");
  13350. if(loc == NULL)
  13351. {
  13352. connectorIdIsNULL = TRUE;
  13353. }
  13354. else
  13355. {
  13356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13357. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13358. {
  13359. sstr[c] = loc[strlen("connectorId")+2+c];
  13360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13361. c++;
  13362. }
  13363. sstr[c] = '\0';
  13364. connectorIdInt = atoi(sstr);
  13365. }
  13366. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13367. {
  13368. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13369. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13370. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13371. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13372. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13373. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13374. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13375. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13376. {
  13377. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13378. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13379. return TRUE;
  13380. }
  13381. else
  13382. {
  13383. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13384. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13385. }
  13386. }
  13387. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13388. {
  13389. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13390. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13391. return TRUE;
  13392. }
  13393. //==========================
  13394. // Trigger message
  13395. //==========================
  13396. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13397. {
  13398. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13399. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13400. {
  13401. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13402. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13403. }
  13404. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13405. }
  13406. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13407. {
  13408. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13409. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13410. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13411. }
  13412. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13413. {
  13414. //sendBootNotificationRequest();
  13415. server_sign = FALSE;
  13416. }
  13417. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13418. {
  13419. refreshStartTimer(&clientTime.Heartbeat);
  13420. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13421. }
  13422. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13423. {
  13424. if(connectorIdIsNULL == FALSE)
  13425. {
  13426. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13427. {
  13428. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13429. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13430. }
  13431. }
  13432. else
  13433. {
  13434. for(int idx=0;idx< gunTotalNumber;idx++)
  13435. {
  13436. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13437. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13438. }
  13439. }
  13440. }
  13441. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13442. {
  13443. if(connectorIdIsNULL == FALSE)
  13444. {
  13445. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13446. {
  13447. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13448. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13449. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13450. }
  13451. }
  13452. else
  13453. {
  13454. for(int idx=0;idx< gunTotalNumber;idx++)
  13455. {
  13456. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13457. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13458. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13459. }
  13460. }
  13461. }
  13462. return result;
  13463. }
  13464. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13465. {
  13466. mtrace();
  13467. int result = FAIL;
  13468. int connectorIdInt =0;
  13469. char comfirmstr[20]={0};
  13470. int tempIndex = 0;
  13471. json_object *UnlockConnector;
  13472. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13473. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13474. UnlockConnector = json_tokener_parse(payload);
  13475. if(!is_error(UnlockConnector))
  13476. {
  13477. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13478. {
  13479. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13480. }
  13481. }
  13482. json_object_put(UnlockConnector);
  13483. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13484. if(gunTotalNumber == 0)
  13485. {
  13486. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13487. goto end;
  13488. }
  13489. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13490. {
  13491. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13492. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13493. goto end;
  13494. }
  13495. else
  13496. {
  13497. //check Transaction active
  13498. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13499. {
  13500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13501. {
  13502. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13503. }
  13504. else
  13505. {
  13506. tempIndex = connectorIdInt -1;
  13507. }
  13508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13509. {
  13510. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13511. {
  13512. //stop Transaction
  13513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13514. }
  13515. }
  13516. }
  13517. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13518. {
  13519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13520. {
  13521. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13522. }
  13523. else
  13524. {
  13525. tempIndex = connectorIdInt -1;
  13526. }
  13527. for (int index = 0; index < CCS_QUANTITY; index++)
  13528. {
  13529. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13530. {
  13531. //stop Transaction
  13532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13533. }
  13534. }
  13535. }
  13536. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13537. {
  13538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13539. {
  13540. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13541. }
  13542. else
  13543. {
  13544. tempIndex = connectorIdInt -1;
  13545. }
  13546. for (int index = 0; index < GB_QUANTITY; index++)
  13547. {
  13548. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13549. {
  13550. //stop Transaction
  13551. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13552. }
  13553. }
  13554. }
  13555. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13556. {
  13557. tempIndex = connectorIdInt -1;
  13558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13559. {
  13560. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13561. {
  13562. //stop Transaction
  13563. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13564. }
  13565. }
  13566. }
  13567. else
  13568. {
  13569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13570. {
  13571. tempIndex = 2;
  13572. }
  13573. else
  13574. {
  13575. tempIndex = connectorIdInt-1;
  13576. }
  13577. for (int index = 0; index < AC_QUANTITY; index++)
  13578. {
  13579. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13580. {
  13581. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13582. }
  13583. }
  13584. }
  13585. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13586. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13587. result = TRUE;
  13588. return result;
  13589. }
  13590. end:
  13591. //json_object_put(obj); --- remove temporally
  13592. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13593. return result;
  13594. }
  13595. static char UpdateFirmwarepayloadData[300]={0};
  13596. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13597. {
  13598. mtrace();
  13599. int result = FAIL;
  13600. pthread_t t;
  13601. sendUpdateFirmwareConfirmation(uuid);
  13602. memset(UpdateFirmwarepayloadData, 0, 300);
  13603. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13604. if(!interLock.isUpdateFirmwareGoing)
  13605. {
  13606. interLock.isUpdateFirmwareGoing = 1;
  13607. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13608. sleep(1);
  13609. }
  13610. else
  13611. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13612. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13613. return result;
  13614. }
  13615. void *UpdateFirmwareProcess(void *data)
  13616. {
  13617. pthread_detach(pthread_self());
  13618. mtrace();
  13619. int retriesInt =0, retryIntervalInt=0;
  13620. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13621. int port=0;
  13622. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13623. int isSuccess = 0;
  13624. char ftpbuf[1024];
  13625. char temp[1024];
  13626. char * pch;
  13627. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13628. json_object *UpdateFirmware;
  13629. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13630. if(!is_error(UpdateFirmware))
  13631. {
  13632. // Required data
  13633. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13634. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13635. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13636. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13637. // Optional data
  13638. if(json_object_object_get(UpdateFirmware, "retries"))
  13639. {
  13640. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13641. }
  13642. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13643. {
  13644. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13645. }
  13646. }
  13647. json_object_put(UpdateFirmware);
  13648. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13649. memset(path, 0, ARRAY_SIZE(path));
  13650. // Wait retrieveData
  13651. if(strlen(retrieveDatestr) > 10)
  13652. {
  13653. do
  13654. {
  13655. sleep(1);
  13656. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13657. }
  13658. // Ready to download
  13659. system("rm -f /mnt/*");
  13660. if(strncmp(locationstr,"http", 4) == 0)
  13661. {
  13662. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13663. sprintf(ftppath,"/%s", path);
  13664. DEBUG_INFO("locationstr: %s\n", locationstr);
  13665. DEBUG_INFO("protocol: %s\n",protocol);
  13666. DEBUG_INFO("host: %s\n",host);
  13667. DEBUG_INFO("path: %s\n",path);
  13668. DEBUG_INFO("ftppath: %s\n",ftppath);
  13669. int ftppathlen=strlen(ftppath);
  13670. int i=1;
  13671. char filenametemp[50];
  13672. while(i < ftppathlen)
  13673. {
  13674. int len=ftppathlen-i;
  13675. if(ftppath[len]== 47) // '/' ascll code: 47
  13676. {
  13677. DEBUG_INFO("compare '/' all right\n");
  13678. break;
  13679. }
  13680. i=i+1;
  13681. }
  13682. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13683. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13684. filenametemp[i+1] = 0;
  13685. do
  13686. {
  13687. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13688. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13689. sleep(1);
  13690. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13691. if(!isSuccess)
  13692. {
  13693. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13694. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13695. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13696. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13697. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13698. }
  13699. else
  13700. {
  13701. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13702. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13703. }
  13704. retriesInt--;
  13705. }while((isSuccess == 0)&&(retriesInt >= 0));
  13706. }
  13707. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13708. {
  13709. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13710. memset(temp, 0, ARRAY_SIZE(temp));
  13711. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13712. strcpy(ftpbuf, locationstr);
  13713. int ftppathlen=strlen(ftpbuf);
  13714. int i=1;
  13715. char filenametemp[50];
  13716. while(i < ftppathlen)
  13717. {
  13718. int len=ftppathlen-i;
  13719. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13720. {
  13721. DEBUG_INFO(" compare '/' all right\n");
  13722. break;
  13723. }
  13724. i=i+1;
  13725. }
  13726. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13727. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13728. filenametemp[i+1] = 0;
  13729. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13730. pch=strchr(temp,'@');
  13731. if(pch==NULL)
  13732. {
  13733. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13734. protocol, host, &port, path);
  13735. strcpy(user,"anonymous");
  13736. strcpy(password,"");
  13737. }
  13738. else
  13739. {
  13740. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13741. protocol, user, host, &port, path);
  13742. }
  13743. sscanf(host,"%[^/]%s",host1, path1);
  13744. sprintf(ftppath,"%s:/%s", host,path);
  13745. if(port == 0)
  13746. {
  13747. port = 21;
  13748. }
  13749. do
  13750. {
  13751. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13752. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13753. sleep(1);
  13754. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13755. if(!isSuccess)
  13756. {
  13757. //BulldogUtil.sleepMs(interval*1000);
  13758. DEBUG_INFO("Update firmware request and download file fail.\n");
  13759. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13760. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13761. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13762. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13763. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13764. }
  13765. else
  13766. {
  13767. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13768. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13769. }
  13770. retriesInt--;
  13771. }while((!isSuccess)&&(retriesInt >= 0));
  13772. }
  13773. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13774. {
  13775. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13776. memset(temp, 0, ARRAY_SIZE(temp));
  13777. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13778. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13779. int ftppathlen=strlen(ftpbuf);
  13780. int i=1;
  13781. char filenametemp[50];
  13782. while(i < ftppathlen)
  13783. {
  13784. int len=ftppathlen-i;
  13785. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13786. {
  13787. DEBUG_INFO(" compare '/' all right\n");
  13788. break;
  13789. }
  13790. i=i+1;
  13791. }
  13792. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13793. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13794. filenametemp[i+1] = 0;
  13795. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13796. pch=strchr(temp,'@');
  13797. if(pch==NULL)
  13798. {
  13799. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13800. protocol, host, &port, path);
  13801. strcpy(user,"anonymous");
  13802. strcpy(password,"");
  13803. }
  13804. else
  13805. {
  13806. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13807. protocol, user, password, host, &port, path);
  13808. }
  13809. sscanf(host,"%[^/]%s",host1, path1);
  13810. sprintf(ftppath,"%s", path1);
  13811. //DEBUG_INFO("protocol =%s\n",protocol);
  13812. //DEBUG_INFO("user =%s\n",user);
  13813. //DEBUG_INFO("password =%s\n",password);
  13814. //DEBUG_INFO("host1 =%s\n",host1);
  13815. //DEBUG_INFO("port =%d\n",port);
  13816. //DEBUG_INFO("path1 =%s\n",path1);
  13817. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13818. //ftpFile(host, user, password, port, ftppath, fname);
  13819. //download firmware pthred
  13820. if(port == 0)
  13821. {
  13822. port = 21;
  13823. }
  13824. do
  13825. {
  13826. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13827. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13828. sleep(1);
  13829. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13830. if(!isSuccess)
  13831. {
  13832. //BulldogUtil.sleepMs(interval*1000);
  13833. DEBUG_INFO("Update firmware request and download file fail.\n");
  13834. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13835. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13836. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13837. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13838. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13839. }
  13840. else
  13841. {
  13842. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13843. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13844. }
  13845. retriesInt--;
  13846. }while((!isSuccess)&&(retriesInt >= 0));
  13847. }
  13848. else
  13849. {
  13850. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13851. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13852. sleep(1);
  13853. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13855. }
  13856. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13857. interLock.isUpdateFirmwareGoing = 0;
  13858. pthread_exit(NULL);
  13859. }
  13860. int handleCertificateSignedRequest(char *uuid, char *payload)
  13861. {
  13862. mtrace();
  13863. int result = PASS;
  13864. json_object *CertificateSigned;
  13865. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13866. CertificateSigned = json_tokener_parse(payload);
  13867. if(!is_error(CertificateSigned))
  13868. {
  13869. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13870. }
  13871. json_object_put(CertificateSigned);
  13872. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13873. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13874. fclose(fp);
  13875. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13876. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13877. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13878. sendCertificateSignedConfirmation(uuid);
  13879. return result;
  13880. }
  13881. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13882. {
  13883. mtrace();
  13884. int result = PASS;
  13885. json_object *DeleteCertificate;
  13886. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13887. DeleteCertificate = json_tokener_parse(payload);
  13888. if(!is_error(DeleteCertificate))
  13889. {
  13890. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13891. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13892. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13893. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13894. }
  13895. json_object_put(DeleteCertificate);
  13896. /*
  13897. * TODO: Delete certificateSigned process
  13898. */
  13899. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13900. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13901. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13902. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13903. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13904. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13905. sendDeleteCertificateConfirmation(uuid);
  13906. return result;
  13907. }
  13908. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13909. {
  13910. mtrace();
  13911. int result = PASS;
  13912. json_object *ExtendedTriggerMessage;
  13913. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13914. ExtendedTriggerMessage = json_tokener_parse(payload);
  13915. if(!is_error(ExtendedTriggerMessage))
  13916. {
  13917. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13918. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13919. {
  13920. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13921. }
  13922. else
  13923. {
  13924. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13925. }
  13926. }
  13927. json_object_put(ExtendedTriggerMessage);
  13928. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13929. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13930. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13931. {
  13932. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13933. }
  13934. else
  13935. {
  13936. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13937. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13938. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13939. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13940. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13941. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13942. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13943. {
  13944. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13945. }
  13946. else
  13947. {
  13948. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13949. }
  13950. }
  13951. sendExtendedTriggerMessageConfirmation(uuid);
  13952. //==========================
  13953. // Trigger message
  13954. //==========================
  13955. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13956. {
  13957. //sendBootNotificationRequest();
  13958. server_sign = FALSE;
  13959. }
  13960. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13961. {
  13962. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13963. }
  13964. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13965. {
  13966. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13967. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13968. {
  13969. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13970. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13971. }
  13972. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13973. }
  13974. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13975. {
  13976. refreshStartTimer(&clientTime.Heartbeat);
  13977. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13978. }
  13979. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13980. {
  13981. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13982. {
  13983. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13984. }
  13985. else
  13986. {
  13987. for(int idx=0;idx< gunTotalNumber;idx++)
  13988. {
  13989. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13990. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13991. }
  13992. }
  13993. }
  13994. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13995. {
  13996. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13997. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13998. {
  13999. 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\" &");
  14000. }
  14001. }
  14002. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14003. {
  14004. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14005. {
  14006. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14007. }
  14008. else
  14009. {
  14010. for(int idx=0;idx< gunTotalNumber;idx++)
  14011. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14012. }
  14013. }
  14014. return result;
  14015. }
  14016. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14017. {
  14018. mtrace();
  14019. int result = PASS;
  14020. json_object *GetInstalledCertificateIds;
  14021. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14022. GetInstalledCertificateIds = json_tokener_parse(payload);
  14023. if(!is_error(GetInstalledCertificateIds))
  14024. {
  14025. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14026. }
  14027. json_object_put(GetInstalledCertificateIds);
  14028. /*
  14029. * TODO: Return installed certificate process
  14030. */
  14031. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14032. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14033. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14034. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14035. sendGetInstalledCertificateIdsConfirmation(uuid);
  14036. return result;
  14037. }
  14038. int handleGetLogRequest(char *uuid, char *payload)
  14039. {
  14040. mtrace();
  14041. int result = PASS;
  14042. json_object *GetLog;
  14043. DEBUG_INFO("handleGetLogRequest...\n");
  14044. GetLog = json_tokener_parse(payload);
  14045. if(!is_error(GetLog))
  14046. {
  14047. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14048. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14049. if(json_object_object_get(GetLog, "retries") != NULL)
  14050. {
  14051. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14052. }
  14053. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14054. {
  14055. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14056. }
  14057. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14058. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14059. {
  14060. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14061. }
  14062. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14063. {
  14064. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14065. }
  14066. }
  14067. json_object_put(GetLog);
  14068. /*
  14069. * TODO: Upload log process
  14070. */
  14071. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  14072. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  14073. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  14074. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  14075. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  14076. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  14077. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  14078. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  14079. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14080. sendGetLogConfirmation(uuid);
  14081. return result;
  14082. }
  14083. int handleInstallCertificateRequest(char *uuid, char *payload)
  14084. {
  14085. mtrace();
  14086. int result = PASS;
  14087. json_object *InstallCertificate;
  14088. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14089. InstallCertificate = json_tokener_parse(payload);
  14090. if(!is_error(InstallCertificate))
  14091. {
  14092. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14093. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14094. /*
  14095. * TODO: Install certificate process
  14096. */
  14097. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14098. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14099. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14100. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14101. sendInstallCertificateConfirmation(uuid);
  14102. }
  14103. json_object_put(InstallCertificate);
  14104. return result;
  14105. }
  14106. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14107. {
  14108. mtrace();
  14109. int result = PASS;
  14110. json_object *SignedUpdateFirmware;
  14111. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14112. SignedUpdateFirmware = json_tokener_parse(payload);
  14113. if(!is_error(SignedUpdateFirmware))
  14114. {
  14115. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14116. {
  14117. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14118. }
  14119. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14120. {
  14121. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14122. }
  14123. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14124. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14125. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14126. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14127. {
  14128. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14129. }
  14130. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14131. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14132. }
  14133. json_object_put(SignedUpdateFirmware);
  14134. /*
  14135. * TODO: Upgrade firmware process
  14136. */
  14137. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14138. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  14139. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  14140. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  14141. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14142. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  14143. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  14144. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14145. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14146. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  14147. sendInstallCertificateConfirmation(uuid);
  14148. return result;
  14149. }
  14150. int handleUnknownRequest(char *uuid, char *payload)
  14151. {
  14152. mtrace();
  14153. int result = PASS;
  14154. DEBUG_INFO("handleUnknownRequest...\n");
  14155. sendUnknownConfirmation(uuid);
  14156. result = PASS;
  14157. return result;
  14158. }
  14159. //==========================================
  14160. // Handle server response routine
  14161. //==========================================
  14162. void handleAuthorizeResponse(char *payload, int gun_index)
  14163. {
  14164. mtrace();
  14165. char expiryDatestr[36]={0};
  14166. char parentIdTagstr[21]={0};
  14167. char statusstr[20]={0};
  14168. int expiryDateISNULL=FALSE;
  14169. int parentIdTagISNULL=FALSE;
  14170. DEBUG_INFO("handleAuthorizeResponse...\n");
  14171. json_object *Authorize;
  14172. Authorize = json_tokener_parse(payload);
  14173. if(!is_error(Authorize))
  14174. {
  14175. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14176. {
  14177. // Required data
  14178. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14179. // Optional data
  14180. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14181. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14182. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14183. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14184. }
  14185. }
  14186. json_object_put(Authorize);
  14187. if(expiryDateISNULL == FALSE)
  14188. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14189. if(parentIdTagISNULL == FALSE)
  14190. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14191. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14192. //Update idTag information to authorization cache if supproted
  14193. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14194. {
  14195. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14196. }
  14197. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14198. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14199. authorizeRetryTimes = 0;
  14200. }
  14201. void handleBootNotificationResponse(char *payload, int gun_index)
  14202. {
  14203. mtrace();
  14204. char statusStr[12]={0};
  14205. char currentTimeStr[30]={0};
  14206. int intervalInt = 0;
  14207. DEBUG_INFO("handleBootNotificationResponse...\n");
  14208. json_object *BootNotification;
  14209. BootNotification = json_tokener_parse(payload);
  14210. if(!is_error(BootNotification))
  14211. {
  14212. // Required data
  14213. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14214. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14215. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14216. }
  14217. json_object_put(BootNotification);
  14218. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14219. BootNotificationInterval = intervalInt;
  14220. //write back to ShmOCPP16Data->BootNotification
  14221. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14222. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14223. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14224. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14225. {
  14226. BootNotificationInterval = 0;
  14227. if((intervalInt == 0) || (intervalInt >= 10))
  14228. {
  14229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14230. HeartBeatWaitTime = intervalInt;
  14231. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14232. }
  14233. server_sign = TRUE;
  14234. server_pending =FALSE;
  14235. }
  14236. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14237. {
  14238. server_pending = TRUE;
  14239. }
  14240. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14241. srand(time(NULL));
  14242. refreshStartTimer(&clientTime.Heartbeat);
  14243. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14244. SetOcppConnStatus(TRUE);
  14245. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14246. }
  14247. void handleDataTransferResponse(char *payload, int gun_index)
  14248. {
  14249. json_object *DataTransfer = json_tokener_parse(payload);
  14250. if(!is_error(DataTransfer))
  14251. {
  14252. // Required data
  14253. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14254. // Optional data
  14255. if(json_object_object_get(DataTransfer, "data") != NULL)
  14256. {
  14257. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14258. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14259. if(!is_error(Data))
  14260. {
  14261. if(json_object_object_get(Data, "msgId") != NULL)
  14262. {
  14263. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14264. {
  14265. 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")));
  14266. }
  14267. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14268. {
  14269. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14270. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14271. }
  14272. }
  14273. }
  14274. json_object_put(Data);
  14275. }
  14276. }
  14277. json_object_put(DataTransfer);
  14278. }
  14279. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14280. {
  14281. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14282. //struct json_object *obj;
  14283. // obj = json_tokener_parse(payload);
  14284. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14285. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14286. //No fields are defined.
  14287. }
  14288. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14289. {
  14290. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14291. //struct json_object *obj;
  14292. // obj = json_tokener_parse(payload);
  14293. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14294. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14295. //No fields are defined.
  14296. }
  14297. void handleHeartbeatResponse(char *payload, int gun_index)
  14298. {
  14299. mtrace();
  14300. DEBUG_INFO("handleHeartbeatResponse...\n");
  14301. json_object *Heartbeat;
  14302. Heartbeat = json_tokener_parse(payload);
  14303. if(!is_error(Heartbeat))
  14304. {
  14305. // Required data
  14306. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14307. }
  14308. json_object_put(Heartbeat);
  14309. if(FirstHeartBeat == 0)
  14310. {
  14311. FirstHeartBeat = 1;
  14312. DEBUG_INFO("FirstHeartBeat \n");
  14313. }
  14314. HeartBeatWithNOResponse = 0;
  14315. refreshStartTimer(&clientTime.Heartbeat);
  14316. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14317. }
  14318. void handleMeterValuesResponse(char *payload, int gun_index)
  14319. {
  14320. mtrace();
  14321. DEBUG_INFO("handleMeterValuesResponse...\n");
  14322. isQueueSendable = 1;
  14323. }
  14324. void handleStartTransactionResponse(char *payload, int gun_index)
  14325. {
  14326. mtrace();
  14327. //int transactionIdInt = 0;
  14328. FILE *outfile;
  14329. char data[100]={0};
  14330. DEBUG_INFO("handleStartTransactionResponse...\n");
  14331. json_object *StartTransaction;
  14332. StartTransaction = json_tokener_parse(payload);
  14333. if(!is_error(StartTransaction))
  14334. {
  14335. // Required data
  14336. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14337. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14338. // Optional data
  14339. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14340. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14341. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14342. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14343. }
  14344. json_object_put(StartTransaction);
  14345. OCPP_updatePeriodEnergy(gun_index);
  14346. //-----------Start : write to the Queue TransactionId file -----------------//
  14347. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14348. {}
  14349. else
  14350. {
  14351. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14352. if(log == NULL)
  14353. {
  14354. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14355. return ;
  14356. }
  14357. else
  14358. {
  14359. fclose(log);
  14360. }
  14361. }
  14362. // open file for writing
  14363. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14364. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14365. {
  14366. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14367. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14368. fputs(data, outfile);
  14369. fclose (outfile);
  14370. }
  14371. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14372. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14373. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14374. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14375. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14376. isQueueSendable = 1;
  14377. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14378. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14379. }
  14380. void handleStatusNotificationResponse(char *payload, int gun_index)
  14381. {
  14382. mtrace();
  14383. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14384. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14385. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14386. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14387. }
  14388. void handleStopTransactionnResponse(char *payload, int gun_index)
  14389. {
  14390. mtrace();
  14391. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14392. json_object *StopTransaction;
  14393. StopTransaction = json_tokener_parse(payload);
  14394. if(!is_error(StopTransaction))
  14395. {
  14396. // Optional data
  14397. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14398. {
  14399. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14400. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14402. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14403. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14404. }
  14405. }
  14406. json_object_put(StopTransaction);
  14407. isQueueSendable = 1;
  14408. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14409. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14410. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14411. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14412. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14413. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14414. }
  14415. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14416. {
  14417. mtrace();
  14418. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14419. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14420. }
  14421. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14422. {
  14423. mtrace();
  14424. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14425. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14426. }
  14427. void handleSignCertificateResponse(char *payload, int gun_index)
  14428. {
  14429. mtrace();
  14430. DEBUG_INFO("handleSignCertificateResponse...\n");
  14431. json_object *SignCertificate;
  14432. SignCertificate = json_tokener_parse(payload);
  14433. if(!is_error(SignCertificate))
  14434. {
  14435. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14436. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14437. }
  14438. json_object_put(SignCertificate);
  14439. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14440. }
  14441. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14442. {
  14443. mtrace();
  14444. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14445. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14446. }
  14447. //==========================================
  14448. // Handle Error routine
  14449. //==========================================
  14450. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14451. {
  14452. mtrace();
  14453. #ifdef SystemLogMessage
  14454. DEBUG_INFO("errorCode: %s\n", errorCode);
  14455. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14456. DEBUG_INFO("errorDetails: %s\n", payload);
  14457. #endif
  14458. }
  14459. //===============================================
  14460. // Common routine
  14461. //===============================================
  14462. int initialConfigurationTable(void)
  14463. {
  14464. //clock_t start_t, end_t, total_t;
  14465. FILE *fp;
  14466. FILE *outfile;
  14467. char str[512]={0};
  14468. char sstr[256]={0};
  14469. int c = 0;
  14470. char *loc;
  14471. int confVersion = 17;
  14472. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14473. //start_t = clock();
  14474. //printf("Starting of the program, start_t = %ld\n", start_t);
  14475. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14476. // Check configuration file size is correct
  14477. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14478. {
  14479. struct stat st;
  14480. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14481. if(st.st_size < 3100)
  14482. {
  14483. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14484. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14485. }
  14486. }
  14487. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14488. {
  14489. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14490. if(outfile == NULL)
  14491. {
  14492. DEBUG_INFO("Error opening file\n");
  14493. return FALSE;
  14494. }
  14495. /*Core Profile*/
  14496. //AllowOfflineTxForUnknownId
  14497. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14501. //AuthorizationCacheEnabled
  14502. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14506. //AuthorizeRemoteTxRequests
  14507. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14511. //BlinkRepeat
  14512. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14516. //ClockAlignedDataInterval
  14517. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14521. //ConnectionTimeOut
  14522. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14526. //GetConfigurationMaxKeys
  14527. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14531. // HeartbeatInterval
  14532. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14536. // LightIntensity
  14537. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14541. // LocalAuthorizeOffline
  14542. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14546. // LocalPreAuthorize
  14547. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14551. // MaxEnergyOnInvalidId
  14552. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14556. // MeterValuesAlignedData
  14557. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14560. 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" );
  14561. else
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14564. // MeterValuesAlignedDataMaxLength
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14569. else
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14572. // MeterValuesSampledData
  14573. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14576. 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" );
  14577. else
  14578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14580. // MeterValuesSampledDataMaxLength
  14581. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14585. else
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14588. // MeterValueSampleInterval
  14589. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14593. // MinimumStatusDuration
  14594. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14597. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14599. // NumberOfConnectors
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14603. {
  14604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14605. }
  14606. else
  14607. {
  14608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14609. }
  14610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14611. // ResetRetries
  14612. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14616. // ConnectorPhaseRotation
  14617. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14621. // ConnectorPhaseRotationMaxLength
  14622. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14626. // StopTransactionOnEVSideDisconnect
  14627. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14631. // StopTransactionOnInvalidId
  14632. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14636. // StopTxnAlignedData
  14637. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14641. // StopTxnAlignedDataMaxLength
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14646. // StopTxnSampledData
  14647. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14651. else
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14654. // StopTxnSampledDataMaxLength
  14655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14658. {
  14659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14660. }
  14661. else
  14662. {
  14663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14664. }
  14665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14666. // SupportedFeatureProfiles
  14667. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14671. // SupportedFeatureProfilesMaxLength
  14672. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14676. // TransactionMessageAttempts
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14680. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14682. // TransactionMessageRetryInterval
  14683. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14686. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14688. // UnlockConnectorOnEVSideDisconnect
  14689. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14693. // WebSocketPingInterval
  14694. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14698. // QueueOffLineMeterValues
  14699. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14703. // AuthorizationKey
  14704. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14708. // SecurityProfile
  14709. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14713. // DefaultPrice
  14714. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14718. // CustomDisplayCostAndPrice
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14723. // CustomIdleFeeAfterStop
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14728. // TimeOffset
  14729. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14733. // NextTimeOffsetTransitionDateTime
  14734. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14738. // TimeOffsetNextTransition
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14743. // SystemUptimeSec
  14744. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14748. // FreeVend
  14749. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14753. // FreeVendIdtag
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14758. // OcppServer
  14759. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14761. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14763. // MaintainServer
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14766. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14768. // StatusNotificationPeriodically
  14769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14773. // StatusNotificationInterval
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14778. // PreAuthAmount
  14779. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14783. // isEnableLocalPowerSharing
  14784. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14788. // PowerSharingServerIP
  14789. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14791. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14793. // EVCCID_PREFIX
  14794. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14798. // OffLineMaxChargingPower
  14799. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14803. // Configuration Version
  14804. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14808. //* Local Auth List Management Profile*/
  14809. #if 0
  14810. //For OCTT Test Case
  14811. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14814. #endif
  14815. #if 1
  14816. //LocalAuthListEnabled
  14817. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14821. #endif
  14822. //LocalAuthListMaxLength
  14823. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14827. //SendLocalListMaxLength
  14828. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14832. //ReserveConnectorZeroSupported
  14833. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14837. //* Smart Charging Profile */
  14838. //ChargeProfileMaxStackLevel
  14839. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14843. // ChargingScheduleAllowedChargingRateUnit
  14844. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14848. // ChargingScheduleMaxPeriods
  14849. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14853. // ConnectorSwitch3to1PhaseSupported
  14854. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14858. // MaxChargingProfilesInstalled
  14859. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14863. fclose(outfile);
  14864. }
  14865. else
  14866. {
  14867. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14868. char keystr[60]={0};
  14869. char readonlystr[10]={0};
  14870. char valuestr[256]={0};
  14871. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14872. if(fp == NULL) {
  14873. DEBUG_INFO("Error opening file");
  14874. return FALSE;
  14875. }
  14876. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14877. {
  14878. //DEBUG_INFO("Get Configuration \n");
  14879. if(strlen(str) > 0)
  14880. {
  14881. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14882. //*************************key*********************************/
  14883. if(strstr(str, "key") != NULL)
  14884. {
  14885. loc = strstr(str, "key");
  14886. c = 0;
  14887. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14888. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14889. {
  14890. sstr[c] = loc[strlen("key")+3+c];
  14891. c++;
  14892. }
  14893. sstr[c] = '\0';
  14894. strcpy(keystr,sstr);
  14895. }
  14896. //*************************readonly*********************************/
  14897. if(strstr(str, "readonly") != NULL)
  14898. {
  14899. loc = strstr(str, "readonly");
  14900. c = 0;
  14901. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14902. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14903. {
  14904. sstr[c] = loc[strlen("readonly")+2+c];
  14905. c++;
  14906. }
  14907. sstr[c] = '\0';
  14908. strcpy(readonlystr,sstr);
  14909. }
  14910. //*************************value*********************************/
  14911. if(strstr(str, "value") != NULL)
  14912. {
  14913. loc = strstr(str, "value");
  14914. c = 0;
  14915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14916. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14917. {
  14918. sstr[c] = loc[strlen("value")+3+c];
  14919. c++;
  14920. }
  14921. sstr[c] = '\0';
  14922. strcpy(valuestr,sstr);
  14923. }
  14924. // DEBUG_INFO("keystr=%s\n",keystr);
  14925. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14926. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14927. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14928. {
  14929. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14930. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14932. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14933. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14934. }
  14935. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14936. {
  14937. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14938. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14940. }
  14941. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14942. {
  14943. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14945. }
  14946. if(strcmp(keystr, "BlinkRepeat") == 0)
  14947. {
  14948. //Charger.BlinkRepeat = Integer.parseInt(value);
  14949. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14951. }
  14952. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14953. {
  14954. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14956. }
  14957. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14958. {
  14959. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14961. }
  14962. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14963. {
  14964. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14966. }
  14967. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14968. {
  14969. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14971. HeartBeatWaitTime = atoi(valuestr);
  14972. }
  14973. if(strcmp(keystr, "LightIntensity") == 0)
  14974. {
  14975. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14977. }
  14978. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14979. {
  14980. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14982. }
  14983. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14984. {
  14985. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14987. }
  14988. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14989. {
  14990. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14992. }
  14993. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14994. {
  14995. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14997. }
  14998. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14999. {
  15000. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15002. }
  15003. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15004. {
  15005. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15007. }
  15008. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15009. {
  15010. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15012. }
  15013. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15014. {
  15015. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15017. }
  15018. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15019. {
  15020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15022. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15023. }
  15024. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15025. {
  15026. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15028. }
  15029. if(strcmp(keystr, "ResetRetries") == 0)
  15030. {
  15031. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15033. }
  15034. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15035. {
  15036. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15038. }
  15039. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15040. {
  15041. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15043. }
  15044. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15045. {
  15046. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15048. }
  15049. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15050. {
  15051. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15053. }
  15054. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15055. {
  15056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15058. }
  15059. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15060. {
  15061. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15063. }
  15064. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15065. {
  15066. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15068. }
  15069. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15070. {
  15071. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15073. }
  15074. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15075. {
  15076. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15078. }
  15079. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15080. {
  15081. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15083. }
  15084. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15085. {
  15086. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15088. TransactionMessageAttemptsValue = atoi(valuestr);
  15089. }
  15090. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15091. {
  15092. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15094. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15095. }
  15096. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15097. {
  15098. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15100. }
  15101. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15102. {
  15103. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15105. }
  15106. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15107. {
  15108. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15110. }
  15111. if(strcmp(keystr, "AuthorizationKey") == 0)
  15112. {
  15113. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15114. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15116. }
  15117. if(strcmp(keystr, "SecurityProfile") == 0)
  15118. {
  15119. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15121. }
  15122. if(strcmp(keystr, "DefaultPrice") == 0)
  15123. {
  15124. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15126. }
  15127. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15128. {
  15129. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15131. }
  15132. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15133. {
  15134. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15136. }
  15137. if(strcmp(keystr, "TimeOffset") == 0)
  15138. {
  15139. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15141. }
  15142. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15143. {
  15144. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15146. }
  15147. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15148. {
  15149. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15151. }
  15152. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15153. {
  15154. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15156. }
  15157. if(strcmp(keystr, "FreeVend") == 0)
  15158. {
  15159. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15161. }
  15162. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15163. {
  15164. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15166. }
  15167. if(strcmp(keystr, "OcppServer") == 0)
  15168. {
  15169. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15170. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15171. }
  15172. if(strcmp(keystr, "MaintainServer") == 0)
  15173. {
  15174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15175. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15176. }
  15177. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15178. {
  15179. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15181. }
  15182. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15183. {
  15184. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15186. }
  15187. if(strcmp(keystr, "PreAuthAmount") == 0)
  15188. {
  15189. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15191. }
  15192. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15193. {
  15194. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15196. }
  15197. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15198. {
  15199. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15200. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15201. }
  15202. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15203. {
  15204. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15206. }
  15207. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15208. {
  15209. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15211. }
  15212. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15213. {
  15214. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15216. }
  15217. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15218. {
  15219. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15221. }
  15222. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15223. {
  15224. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15226. }
  15227. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15228. {
  15229. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15231. }
  15232. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15233. {
  15234. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15236. }
  15237. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15238. {
  15239. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15241. }
  15242. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15243. {
  15244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15246. }
  15247. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15248. {
  15249. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15251. }
  15252. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15253. {
  15254. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15256. }
  15257. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15258. {
  15259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15261. }
  15262. }
  15263. }
  15264. fclose(fp);
  15265. }
  15266. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15267. {
  15268. return PASS;
  15269. }
  15270. else
  15271. {
  15272. return FAIL;
  15273. }
  15274. }
  15275. void StoreConfigurationTable(void)
  15276. {
  15277. FILE *outfile;
  15278. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15279. if(outfile == NULL)
  15280. {
  15281. DEBUG_INFO("Error opening file");
  15282. return ;
  15283. }
  15284. /*Core Profile*/
  15285. //AllowOfflineTxForUnknownId
  15286. /*
  15287. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15288. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15291. */
  15292. //DEBUG_INFO("data=%s\n",data);
  15293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15294. //AuthorizationCacheEnabled
  15295. /*
  15296. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15299. */
  15300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15301. //AuthorizeRemoteTxRequests
  15302. /*
  15303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15306. */
  15307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15308. //BlinkRepeat
  15309. /*
  15310. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15313. */
  15314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15315. //ClockAlignedDataInterval
  15316. /*
  15317. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15320. */
  15321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15322. //ConnectionTimeOut
  15323. /*
  15324. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15327. */
  15328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15329. //GetConfigurationMaxKeys
  15330. /*
  15331. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15334. */
  15335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15336. // HeartbeatInterval
  15337. /*
  15338. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15341. */
  15342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15343. // LightIntensity
  15344. /*
  15345. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15348. */
  15349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15350. // LocalAuthorizeOffline
  15351. /*
  15352. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15355. */
  15356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15357. // LocalPreAuthorize
  15358. /*
  15359. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15362. */
  15363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15364. // MaxEnergyOnInvalidId
  15365. /*
  15366. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15369. */
  15370. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15372. // MeterValuesAlignedData
  15373. /*
  15374. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15377. */
  15378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15379. // MeterValuesAlignedDataMaxLength
  15380. /*
  15381. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15384. */
  15385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15386. // MeterValuesSampledData
  15387. /*
  15388. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15391. */
  15392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15393. // MeterValuesSampledDataMaxLength
  15394. /*
  15395. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15398. */
  15399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15400. // MeterValueSampleInterval
  15401. /*
  15402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15405. */
  15406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15407. // MinimumStatusDuration
  15408. /*
  15409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15412. */
  15413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15414. // NumberOfConnectors
  15415. /*
  15416. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15419. {
  15420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15421. }
  15422. else
  15423. {
  15424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15425. }
  15426. */
  15427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15428. // ResetRetries
  15429. /*
  15430. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15433. */
  15434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15435. // ConnectorPhaseRotation
  15436. /*
  15437. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15440. */
  15441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15442. // ConnectorPhaseRotationMaxLength
  15443. /*
  15444. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15447. */
  15448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15449. // StopTransactionOnEVSideDisconnect
  15450. /*
  15451. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15454. */
  15455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15456. // StopTransactionOnInvalidId
  15457. /*
  15458. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15461. */
  15462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15463. // StopTxnAlignedData
  15464. /*
  15465. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15468. */
  15469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15470. // StopTxnAlignedDataMaxLength
  15471. /*
  15472. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15475. */
  15476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15477. // StopTxnSampledData
  15478. /*
  15479. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15482. */
  15483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15484. // StopTxnSampledDataMaxLength
  15485. /*
  15486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15489. */
  15490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15491. // SupportedFeatureProfiles
  15492. /*
  15493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15496. */
  15497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15498. // SupportedFeatureProfilesMaxLength
  15499. /*
  15500. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15503. */
  15504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15505. // TransactionMessageAttempts
  15506. /*
  15507. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15510. */
  15511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15512. // TransactionMessageRetryInterval
  15513. /*
  15514. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15517. */
  15518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15519. // UnlockConnectorOnEVSideDisconnect
  15520. /*
  15521. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15524. */
  15525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15526. // WebSocketPingInterval
  15527. /*
  15528. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15531. */
  15532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15533. // QueueOffLineMeterValues
  15534. /*
  15535. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15538. */
  15539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15540. // AuthorizationKey
  15541. /*
  15542. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15545. */
  15546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15547. // SecurityProfile
  15548. /*
  15549. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15552. */
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15554. // DefaultPrice
  15555. /*
  15556. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15559. */
  15560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15561. // CustomDisplayCostAndPrice
  15562. /*
  15563. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15566. */
  15567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15568. // CustomIdleFeeAfterStop
  15569. /*
  15570. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15573. */
  15574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15575. // TimeOffset
  15576. /*
  15577. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15580. */
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15582. // NextTimeOffsetTransitionDateTime
  15583. /*
  15584. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15587. */
  15588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15589. // TimeOffsetNextTransition
  15590. /*
  15591. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15594. */
  15595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15596. // SystemUptimeSec
  15597. /*
  15598. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15601. */
  15602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15603. // FreeVend
  15604. /*
  15605. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15608. */
  15609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15610. // FreeVendIdtag
  15611. /*
  15612. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15615. */
  15616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15617. // OcppServer
  15618. /*
  15619. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15622. */
  15623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15624. // MaintainServer
  15625. /*
  15626. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15629. */
  15630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15631. // StatusNotificationPeriodically
  15632. /*
  15633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15636. */
  15637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15638. // StatusNotificationInterval
  15639. /*
  15640. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15643. */
  15644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15645. // PreAuthAmount
  15646. /*
  15647. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15650. */
  15651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15652. // isEnableLocalPowerSharing
  15653. /*
  15654. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15657. */
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15659. // PowerSharingServerIP
  15660. /*
  15661. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15664. */
  15665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15666. // EVCCID_PREFIX
  15667. /*
  15668. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15671. */
  15672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15673. // OffLineMaxChargingPower
  15674. /*
  15675. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15678. */
  15679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15680. // ConfigurationVersion
  15681. /*
  15682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15685. */
  15686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15687. //* Local Auth List Management Profile*/
  15688. //LocalAuthListEnabled
  15689. /*
  15690. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15693. */
  15694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15695. //LocalAuthListMaxLength
  15696. /*
  15697. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15700. */
  15701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15702. //SendLocalListMaxLength
  15703. /*
  15704. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15707. */
  15708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15709. //ReserveConnectorZeroSupported
  15710. /*
  15711. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15714. */
  15715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15716. //* Smart Charging Profile */
  15717. //ChargeProfileMaxStackLevel
  15718. /*
  15719. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15722. */
  15723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15724. // ChargingScheduleAllowedChargingRateUnit
  15725. /*
  15726. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15729. */
  15730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15731. // ChargingScheduleMaxPeriods
  15732. /*
  15733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15736. */
  15737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15738. // ConnectorSwitch3to1PhaseSupported
  15739. /*
  15740. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15743. */
  15744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15745. // MaxChargingProfilesInstalled
  15746. /*
  15747. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15750. */
  15751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15752. fclose(outfile);
  15753. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15754. }
  15755. void getKeyValue(char *keyReq)
  15756. {
  15757. int isEmpty = FALSE;
  15758. int isKnowKey = FALSE;
  15759. DEBUG_INFO("keyReq = %s\n", keyReq);
  15760. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15761. isEmpty = TRUE;
  15762. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15763. {
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15767. {
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15769. }
  15770. else
  15771. {
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15773. }
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15775. isKnowKey = TRUE;
  15776. }
  15777. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15778. {
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15782. {
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15784. }
  15785. else
  15786. {
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15788. }
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15790. isKnowKey = TRUE;
  15791. }
  15792. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15793. {
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15797. {
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15799. }
  15800. else
  15801. {
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15803. }
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15805. isKnowKey = TRUE;
  15806. }
  15807. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15808. {
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15812. {
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15814. }
  15815. else
  15816. {
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15818. }
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15820. isKnowKey = TRUE;
  15821. }
  15822. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15823. {
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15827. {
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15829. }
  15830. else
  15831. {
  15832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15833. }
  15834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15835. isKnowKey = TRUE;
  15836. }
  15837. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15838. {
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15842. {
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15844. }
  15845. else
  15846. {
  15847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15848. }
  15849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15850. isKnowKey = TRUE;
  15851. }
  15852. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15853. {
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15857. {
  15858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15859. }
  15860. else
  15861. {
  15862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15863. }
  15864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15865. isKnowKey = TRUE;
  15866. }
  15867. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15868. {
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15872. {
  15873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15874. }
  15875. else
  15876. {
  15877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15878. }
  15879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15880. isKnowKey = TRUE;
  15881. }
  15882. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15883. {
  15884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15887. {
  15888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15889. }
  15890. else
  15891. {
  15892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15893. }
  15894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15895. isKnowKey = TRUE;
  15896. }
  15897. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15898. {
  15899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15902. {
  15903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15904. }
  15905. else
  15906. {
  15907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15908. }
  15909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15910. isKnowKey = TRUE;
  15911. }
  15912. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15913. {
  15914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15917. {
  15918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15919. }
  15920. else
  15921. {
  15922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15923. }
  15924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15925. isKnowKey = TRUE;
  15926. }
  15927. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15928. {
  15929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15932. {
  15933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15934. }
  15935. else
  15936. {
  15937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15938. }
  15939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15940. isKnowKey = TRUE;
  15941. }
  15942. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15943. {
  15944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15947. {
  15948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15949. }
  15950. else
  15951. {
  15952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15953. }
  15954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15955. isKnowKey = TRUE;
  15956. }
  15957. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15958. {
  15959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15962. {
  15963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15964. }
  15965. else
  15966. {
  15967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15968. }
  15969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15970. isKnowKey = TRUE;
  15971. }
  15972. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15973. {
  15974. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15977. {
  15978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15979. }
  15980. else
  15981. {
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15983. }
  15984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15985. isKnowKey = TRUE;
  15986. }
  15987. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15988. {
  15989. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15992. {
  15993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15994. }
  15995. else
  15996. {
  15997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15998. }
  15999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16000. isKnowKey = TRUE;
  16001. }
  16002. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16003. {
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16007. {
  16008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16009. }
  16010. else
  16011. {
  16012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16013. }
  16014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16015. isKnowKey = TRUE;
  16016. }
  16017. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16018. {
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16022. {
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16024. }
  16025. else
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16028. }
  16029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16030. isKnowKey = TRUE;
  16031. }
  16032. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16033. {
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16039. }
  16040. else
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16043. }
  16044. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16046. isKnowKey = TRUE;
  16047. }
  16048. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16049. {
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16053. {
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16055. }
  16056. else
  16057. {
  16058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16059. }
  16060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16061. isKnowKey = TRUE;
  16062. }
  16063. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16064. {
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16068. {
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16070. }
  16071. else
  16072. {
  16073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16074. }
  16075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16076. isKnowKey = TRUE;
  16077. }
  16078. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16079. {
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16083. {
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16085. }
  16086. else
  16087. {
  16088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16089. }
  16090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16091. isKnowKey = TRUE;
  16092. }
  16093. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16094. {
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16098. {
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16100. }
  16101. else
  16102. {
  16103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16104. }
  16105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16106. isKnowKey = TRUE;
  16107. }
  16108. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16109. {
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16113. {
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16115. }
  16116. else
  16117. {
  16118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16119. }
  16120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16121. isKnowKey = TRUE;
  16122. }
  16123. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16124. {
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16128. {
  16129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16130. }
  16131. else
  16132. {
  16133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16134. }
  16135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16136. isKnowKey = TRUE;
  16137. }
  16138. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16139. {
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16143. {
  16144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16145. }
  16146. else
  16147. {
  16148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16149. }
  16150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16151. isKnowKey = TRUE;
  16152. }
  16153. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16154. {
  16155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16158. {
  16159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16160. }
  16161. else
  16162. {
  16163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16164. }
  16165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16166. isKnowKey = TRUE;
  16167. }
  16168. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16169. {
  16170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16173. {
  16174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16175. }
  16176. else
  16177. {
  16178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16179. }
  16180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16181. isKnowKey = TRUE;
  16182. }
  16183. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16184. {
  16185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16188. {
  16189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16190. }
  16191. else
  16192. {
  16193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16194. }
  16195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16196. isKnowKey = TRUE;
  16197. }
  16198. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16199. {
  16200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16203. {
  16204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16205. }
  16206. else
  16207. {
  16208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16209. }
  16210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16211. isKnowKey = TRUE;
  16212. }
  16213. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16214. {
  16215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16218. {
  16219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16220. }
  16221. else
  16222. {
  16223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16224. }
  16225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16226. isKnowKey = TRUE;
  16227. }
  16228. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16229. {
  16230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16233. {
  16234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16235. }
  16236. else
  16237. {
  16238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16239. }
  16240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16241. isKnowKey = TRUE;
  16242. }
  16243. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16244. {
  16245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16248. {
  16249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16250. }
  16251. else
  16252. {
  16253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16254. }
  16255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16256. isKnowKey = TRUE;
  16257. }
  16258. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16259. {
  16260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16263. {
  16264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16265. }
  16266. else
  16267. {
  16268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16269. }
  16270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16271. isKnowKey = TRUE;
  16272. }
  16273. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16274. {
  16275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16278. {
  16279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16280. }
  16281. else
  16282. {
  16283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16284. }
  16285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16286. isKnowKey = TRUE;
  16287. }
  16288. /*
  16289. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16290. {
  16291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16294. {
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16296. }
  16297. else
  16298. {
  16299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16300. }
  16301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16302. isKnowKey = TRUE;
  16303. }*/
  16304. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16305. {
  16306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16309. {
  16310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16311. }
  16312. else
  16313. {
  16314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16315. }
  16316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16317. isKnowKey = TRUE;
  16318. }
  16319. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16320. {
  16321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16324. {
  16325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16326. }
  16327. else
  16328. {
  16329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16330. }
  16331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16332. isKnowKey = TRUE;
  16333. }
  16334. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16335. {
  16336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16339. {
  16340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16341. }
  16342. else
  16343. {
  16344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16345. }
  16346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16347. isKnowKey = TRUE;
  16348. }
  16349. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16350. {
  16351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16354. {
  16355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16356. }
  16357. else
  16358. {
  16359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16360. }
  16361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16362. isKnowKey = TRUE;
  16363. }
  16364. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16365. {
  16366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16369. {
  16370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16371. }
  16372. else
  16373. {
  16374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16375. }
  16376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16377. isKnowKey = TRUE;
  16378. }
  16379. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16380. {
  16381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16384. {
  16385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16386. }
  16387. else
  16388. {
  16389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16390. }
  16391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16392. isKnowKey = TRUE;
  16393. }
  16394. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16395. {
  16396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16399. {
  16400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16401. }
  16402. else
  16403. {
  16404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16405. }
  16406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16407. isKnowKey = TRUE;
  16408. }
  16409. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16410. {
  16411. struct sysinfo s_info;
  16412. int error = sysinfo(&s_info);
  16413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16416. {
  16417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16418. }
  16419. else
  16420. {
  16421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16422. }
  16423. if(error != 0)
  16424. {
  16425. DEBUG_WARN("System uptime get error: %d\n", error);
  16426. }
  16427. else
  16428. {
  16429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16430. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16431. }
  16432. isKnowKey = TRUE;
  16433. }
  16434. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16435. {
  16436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16439. {
  16440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16441. }
  16442. else
  16443. {
  16444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16445. }
  16446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16447. isKnowKey = TRUE;
  16448. }
  16449. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16450. {
  16451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16454. {
  16455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16456. }
  16457. else
  16458. {
  16459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16460. }
  16461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16462. isKnowKey = TRUE;
  16463. }
  16464. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16465. {
  16466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16469. {
  16470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16471. }
  16472. else
  16473. {
  16474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16475. }
  16476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16477. isKnowKey = TRUE;
  16478. }
  16479. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16480. {
  16481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16484. {
  16485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16486. }
  16487. else
  16488. {
  16489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16490. }
  16491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16492. isKnowKey = TRUE;
  16493. }
  16494. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16495. {
  16496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16499. {
  16500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16501. }
  16502. else
  16503. {
  16504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16505. }
  16506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16507. isKnowKey = TRUE;
  16508. }
  16509. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16510. {
  16511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16514. {
  16515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16516. }
  16517. else
  16518. {
  16519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16520. }
  16521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16522. isKnowKey = TRUE;
  16523. }
  16524. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16525. {
  16526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16529. {
  16530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16531. }
  16532. else
  16533. {
  16534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16535. }
  16536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16537. isKnowKey = TRUE;
  16538. }
  16539. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16540. {
  16541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16544. {
  16545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16546. }
  16547. else
  16548. {
  16549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16550. }
  16551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16552. isKnowKey = TRUE;
  16553. }
  16554. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16555. {
  16556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16559. {
  16560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16561. }
  16562. else
  16563. {
  16564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16565. }
  16566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16567. isKnowKey = TRUE;
  16568. }
  16569. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16570. {
  16571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16574. {
  16575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16576. }
  16577. else
  16578. {
  16579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16580. }
  16581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16582. isKnowKey = TRUE;
  16583. }
  16584. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16585. {
  16586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16589. {
  16590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16591. }
  16592. else
  16593. {
  16594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16595. }
  16596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16597. isKnowKey = TRUE;
  16598. }
  16599. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16600. {
  16601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16604. {
  16605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16606. }
  16607. else
  16608. {
  16609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16610. }
  16611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16612. isKnowKey = TRUE;
  16613. }
  16614. #if 1
  16615. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16616. {
  16617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16619. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16620. {
  16621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16622. }
  16623. else
  16624. {
  16625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16626. }
  16627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16628. isKnowKey = TRUE;
  16629. }
  16630. #endif
  16631. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16632. {
  16633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16635. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16636. {
  16637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16638. }
  16639. else
  16640. {
  16641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16642. }
  16643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16644. isKnowKey = TRUE;
  16645. }
  16646. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16647. {
  16648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16650. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16651. {
  16652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16653. }
  16654. else
  16655. {
  16656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16657. }
  16658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16659. isKnowKey = TRUE;
  16660. }
  16661. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16662. {
  16663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16665. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16666. {
  16667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16668. }
  16669. else
  16670. {
  16671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16672. }
  16673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16674. isKnowKey = TRUE;
  16675. }
  16676. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16677. {
  16678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16680. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16681. {
  16682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16683. }
  16684. else
  16685. {
  16686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16687. }
  16688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16689. isKnowKey = TRUE;
  16690. }
  16691. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16692. {
  16693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16695. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16696. {
  16697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16698. }
  16699. else
  16700. {
  16701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16702. }
  16703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16704. isKnowKey = TRUE;
  16705. }
  16706. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16707. {
  16708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16710. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16711. {
  16712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16713. }
  16714. else
  16715. {
  16716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16717. }
  16718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16719. isKnowKey = TRUE;
  16720. }
  16721. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16722. {
  16723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16725. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16726. {
  16727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16728. }
  16729. else
  16730. {
  16731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16732. }
  16733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16734. isKnowKey = TRUE;
  16735. }
  16736. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16737. {
  16738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16740. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16741. {
  16742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16743. }
  16744. else
  16745. {
  16746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16747. }
  16748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16749. isKnowKey = TRUE;
  16750. }
  16751. //=========================================================
  16752. if(!isEmpty && !isKnowKey)
  16753. {
  16754. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16755. strcpy(unknownkey[UnknownKeynum], keyReq);
  16756. UnknownKeynum = UnknownKeynum + 1;
  16757. }
  16758. }
  16759. void processUnkownKey(void)
  16760. {
  16761. DEBUG_INFO("processUnkownKey...\n");
  16762. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16763. for(int index=0; index < UnknownKeynum; index++)
  16764. {
  16765. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16766. {
  16767. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16768. }
  16769. }
  16770. }
  16771. int setKeyValue(char *key, char *value)
  16772. {
  16773. int isSuccess = NotSupported;
  16774. int check_ascii=0;
  16775. char str[501]={0};
  16776. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16777. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16778. {
  16779. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16781. {
  16782. strcpy(str, (const char*)value);
  16783. for(int i = 0; str[i]; i++){
  16784. str[i] = tolower(str[i]);
  16785. }
  16786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16787. isSuccess = ConfigurationStatus_Accepted;
  16788. }
  16789. else
  16790. {
  16791. isSuccess = ConfigurationStatus_Rejected;
  16792. }
  16793. }
  16794. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16795. {
  16796. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16798. {
  16799. strcpy(str, (const char*)value);
  16800. for(int i = 0; str[i]; i++){
  16801. str[i] = tolower(str[i]);
  16802. }
  16803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16804. isSuccess = ConfigurationStatus_Accepted;
  16805. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16806. }
  16807. else
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. }
  16812. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16813. {
  16814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16815. {
  16816. strcpy(str, (const char*)value);
  16817. for(int i = 0; str[i]; i++)
  16818. {
  16819. str[i] = tolower(str[i]);
  16820. }
  16821. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16823. isSuccess = ConfigurationStatus_Accepted;
  16824. }
  16825. else
  16826. {
  16827. isSuccess = ConfigurationStatus_Rejected;
  16828. }
  16829. }
  16830. if(strcmp(key, "BlinkRepeat") == 0)
  16831. {
  16832. //Charger.BlinkRepeat = Integer.parseInt(value);
  16833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16834. {
  16835. check_ascii = value[0];
  16836. if( (check_ascii < 48) || (check_ascii > 57) )
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. else
  16841. {
  16842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16843. isSuccess = ConfigurationStatus_Accepted;
  16844. }
  16845. }
  16846. else
  16847. {
  16848. isSuccess = ConfigurationStatus_Rejected;
  16849. }
  16850. }
  16851. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16852. {
  16853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16854. {
  16855. check_ascii = value[0];
  16856. if( (check_ascii < 48) || (check_ascii > 57) )
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. else
  16861. {
  16862. if((atoi(value) == 0) || (atoi(value) >= 5))
  16863. {
  16864. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. else
  16869. isSuccess = ConfigurationStatus_Rejected;
  16870. }
  16871. }
  16872. else
  16873. {
  16874. isSuccess = ConfigurationStatus_Rejected;
  16875. }
  16876. }
  16877. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16878. {
  16879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16880. {
  16881. check_ascii = value[0];
  16882. if( (check_ascii < 48) || (check_ascii > 57) )
  16883. {
  16884. isSuccess = ConfigurationStatus_Rejected;
  16885. }
  16886. else
  16887. {
  16888. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16890. isSuccess = ConfigurationStatus_Accepted;
  16891. }
  16892. }
  16893. else
  16894. {
  16895. isSuccess = ConfigurationStatus_Rejected;
  16896. }
  16897. }
  16898. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16899. {
  16900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16901. {
  16902. check_ascii = value[0];
  16903. if( (check_ascii < 48) || (check_ascii > 57) )
  16904. {
  16905. isSuccess = ConfigurationStatus_Rejected;
  16906. }
  16907. else
  16908. {
  16909. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16911. isSuccess = ConfigurationStatus_Accepted;
  16912. }
  16913. }
  16914. else
  16915. {
  16916. isSuccess = ConfigurationStatus_Rejected;
  16917. }
  16918. }
  16919. if(strcmp(key, "HeartbeatInterval") == 0)
  16920. {
  16921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16922. {
  16923. check_ascii = value[0];
  16924. if( (check_ascii < 48) || (check_ascii > 57) )
  16925. {
  16926. isSuccess = ConfigurationStatus_Rejected;
  16927. }
  16928. else
  16929. {
  16930. if((atoi(value) == 0) || (atoi(value) >= 10))
  16931. {
  16932. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16934. HeartBeatWaitTime = atoi(value);
  16935. isSuccess = ConfigurationStatus_Accepted;
  16936. }
  16937. else
  16938. {
  16939. isSuccess = ConfigurationStatus_Rejected;
  16940. }
  16941. }
  16942. }
  16943. else
  16944. {
  16945. isSuccess = ConfigurationStatus_Rejected;
  16946. }
  16947. }
  16948. if(strcmp(key, "LightIntensity") == 0)
  16949. {
  16950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16951. {
  16952. check_ascii = value[0];
  16953. if( (check_ascii < 48) || (check_ascii > 57) )
  16954. {
  16955. isSuccess = ConfigurationStatus_Rejected;
  16956. }
  16957. else
  16958. {
  16959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16960. isSuccess = ConfigurationStatus_Accepted;
  16961. }
  16962. }
  16963. else
  16964. {
  16965. isSuccess = ConfigurationStatus_Rejected;
  16966. }
  16967. }
  16968. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16969. {
  16970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16971. {
  16972. strcpy(str, (const char*)value);
  16973. for(int i = 0; str[i]; i++)
  16974. {
  16975. str[i] = tolower(str[i]);
  16976. }
  16977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16978. isSuccess = ConfigurationStatus_Accepted;
  16979. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16980. }
  16981. else
  16982. {
  16983. isSuccess = ConfigurationStatus_Rejected;
  16984. }
  16985. }
  16986. if(strcmp(key, "LocalPreAuthorize") == 0)
  16987. {
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16989. {
  16990. strcpy(str, (const char*)value);
  16991. for(int i = 0; str[i]; i++)
  16992. {
  16993. str[i] = tolower(str[i]);
  16994. }
  16995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16996. isSuccess = ConfigurationStatus_Accepted;
  16997. }
  16998. else
  16999. {
  17000. isSuccess = ConfigurationStatus_Rejected;
  17001. }
  17002. }
  17003. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17004. {
  17005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17006. {
  17007. check_ascii = value[0];
  17008. if( (check_ascii < 48) || (check_ascii > 57) )
  17009. {
  17010. isSuccess = ConfigurationStatus_Rejected;
  17011. }
  17012. else
  17013. {
  17014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17015. isSuccess = ConfigurationStatus_Accepted;
  17016. }
  17017. }
  17018. else
  17019. {
  17020. isSuccess = ConfigurationStatus_Rejected;
  17021. }
  17022. }
  17023. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17024. {
  17025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17026. {
  17027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17028. isSuccess = ConfigurationStatus_Accepted;
  17029. }
  17030. else
  17031. {
  17032. isSuccess = ConfigurationStatus_Rejected;
  17033. }
  17034. }
  17035. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17036. {
  17037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17038. {
  17039. check_ascii = value[0];
  17040. if( (check_ascii < 48) || (check_ascii > 57) )
  17041. {
  17042. isSuccess = ConfigurationStatus_Rejected;
  17043. }
  17044. else
  17045. {
  17046. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17048. isSuccess = ConfigurationStatus_Accepted;
  17049. }
  17050. }
  17051. else
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. }
  17056. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17057. {
  17058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17059. {
  17060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17061. isSuccess = ConfigurationStatus_Accepted;
  17062. }
  17063. else
  17064. {
  17065. isSuccess = ConfigurationStatus_Rejected;
  17066. }
  17067. }
  17068. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17069. {
  17070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17071. {
  17072. check_ascii = value[0];
  17073. if( (check_ascii < 48) || (check_ascii > 57) )
  17074. {
  17075. isSuccess = ConfigurationStatus_Rejected;
  17076. }
  17077. else
  17078. {
  17079. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17081. isSuccess = ConfigurationStatus_Accepted;
  17082. }
  17083. }
  17084. else
  17085. {
  17086. isSuccess = ConfigurationStatus_Rejected;
  17087. }
  17088. }
  17089. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17090. {
  17091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17092. {
  17093. check_ascii = value[0];
  17094. if( (check_ascii < 48) || (check_ascii > 57) )
  17095. {
  17096. isSuccess = ConfigurationStatus_Rejected;
  17097. }
  17098. else
  17099. {
  17100. if((atoi(value) == 0) || (atoi(value) >= 3))
  17101. {
  17102. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17104. isSuccess = ConfigurationStatus_Accepted;
  17105. }
  17106. else
  17107. {
  17108. isSuccess = ConfigurationStatus_Rejected;
  17109. }
  17110. }
  17111. }
  17112. else
  17113. {
  17114. isSuccess = ConfigurationStatus_Rejected;
  17115. }
  17116. }
  17117. if(strcmp(key, "MinimumStatusDuration") == 0)
  17118. {
  17119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17120. {
  17121. check_ascii = value[0];
  17122. if( (check_ascii < 48) || (check_ascii > 57) )
  17123. {
  17124. isSuccess = ConfigurationStatus_Rejected;
  17125. }
  17126. else
  17127. {
  17128. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17129. {
  17130. isSuccess = ConfigurationStatus_Rejected;
  17131. }
  17132. else
  17133. {
  17134. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17136. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17137. isSuccess = ConfigurationStatus_Accepted;
  17138. }
  17139. }
  17140. }
  17141. else
  17142. {
  17143. isSuccess = ConfigurationStatus_Rejected;
  17144. }
  17145. }
  17146. if(strcmp(key, "NumberOfConnectors") == 0)
  17147. {
  17148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17149. {
  17150. check_ascii = value[0];
  17151. if( (check_ascii < 48) || (check_ascii > 57) )
  17152. {
  17153. isSuccess = ConfigurationStatus_Rejected;
  17154. }
  17155. else
  17156. {
  17157. //Charger.ResetRetries = Integer.parseInt(value);
  17158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17159. isSuccess = ConfigurationStatus_Accepted;
  17160. }
  17161. }
  17162. else
  17163. {
  17164. isSuccess = ConfigurationStatus_Rejected;
  17165. }
  17166. }
  17167. if(strcmp(key, "ResetRetries") == 0)
  17168. {
  17169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17170. {
  17171. check_ascii = value[0];
  17172. if( (check_ascii < 48) || (check_ascii > 57) )
  17173. {
  17174. isSuccess = ConfigurationStatus_Rejected;
  17175. }
  17176. else
  17177. {
  17178. //Charger.ResetRetries = Integer.parseInt(value);
  17179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17180. isSuccess = ConfigurationStatus_Accepted;
  17181. }
  17182. }
  17183. else
  17184. {
  17185. isSuccess = ConfigurationStatus_Rejected;
  17186. }
  17187. }
  17188. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17189. {
  17190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17191. {
  17192. strcpy(str, (const char*)value);
  17193. for(int i = 0; str[i]; i++)
  17194. {
  17195. str[i] = tolower(str[i]);
  17196. }
  17197. if(strcmp(str, "notapplicable")== 0)
  17198. {
  17199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17200. isSuccess = ConfigurationStatus_Accepted;
  17201. }
  17202. else if(strcmp(str, "unknown")== 0)
  17203. {
  17204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17205. isSuccess = ConfigurationStatus_Accepted;
  17206. }
  17207. else if(strcmp(str, "rst")== 0)
  17208. {
  17209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17210. isSuccess = ConfigurationStatus_Accepted;
  17211. }
  17212. else if(strcmp(str, "rts")== 0)
  17213. {
  17214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17215. isSuccess = ConfigurationStatus_Accepted;
  17216. }
  17217. else if(strcmp(str, "srt")== 0)
  17218. {
  17219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17220. isSuccess = ConfigurationStatus_Accepted;
  17221. }
  17222. else if(strcmp(str, "str")== 0)
  17223. {
  17224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17225. isSuccess = ConfigurationStatus_Accepted;
  17226. }
  17227. else if(strcmp(str, "trs")== 0)
  17228. {
  17229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17230. isSuccess = ConfigurationStatus_Accepted;
  17231. }
  17232. else if(strcmp(str, "tsr")== 0)
  17233. {
  17234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17235. isSuccess = ConfigurationStatus_Accepted;
  17236. }
  17237. else
  17238. {
  17239. isSuccess = ConfigurationStatus_Rejected;
  17240. }
  17241. }
  17242. else
  17243. {
  17244. isSuccess = ConfigurationStatus_Rejected;
  17245. }
  17246. }
  17247. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17248. {
  17249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17250. {
  17251. check_ascii = value[0];
  17252. if( (check_ascii < 48) || (check_ascii > 57) )
  17253. {
  17254. isSuccess = ConfigurationStatus_Rejected;
  17255. }
  17256. else
  17257. {
  17258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17259. isSuccess = ConfigurationStatus_Accepted;
  17260. }
  17261. }
  17262. else
  17263. {
  17264. isSuccess = ConfigurationStatus_Rejected;
  17265. }
  17266. }
  17267. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17268. {
  17269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17270. {
  17271. strcpy(str, (const char*)value);
  17272. for(int i = 0; str[i]; i++)
  17273. {
  17274. str[i] = tolower(str[i]);
  17275. }
  17276. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17278. isSuccess = ConfigurationStatus_Accepted;
  17279. }
  17280. else
  17281. {
  17282. isSuccess = ConfigurationStatus_Rejected;
  17283. }
  17284. }
  17285. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17286. {
  17287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17288. {
  17289. strcpy(str, (const char*)value);
  17290. for(int i = 0; str[i]; i++)
  17291. {
  17292. str[i] = tolower(str[i]);
  17293. }
  17294. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17296. isSuccess = ConfigurationStatus_Accepted;
  17297. }
  17298. else
  17299. {
  17300. isSuccess = ConfigurationStatus_Rejected;
  17301. }
  17302. }
  17303. if(strcmp(key, "StopTxnAlignedData") == 0)
  17304. {
  17305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17306. {
  17307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17308. isSuccess = ConfigurationStatus_Accepted;
  17309. }
  17310. else
  17311. {
  17312. isSuccess = ConfigurationStatus_Rejected;
  17313. }
  17314. }
  17315. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17316. {
  17317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17318. {
  17319. check_ascii = value[0];
  17320. if( (check_ascii < 48) || (check_ascii > 57) )
  17321. {
  17322. isSuccess = ConfigurationStatus_Rejected;
  17323. }
  17324. else
  17325. {
  17326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17327. isSuccess = ConfigurationStatus_Accepted;
  17328. }
  17329. }
  17330. else
  17331. {
  17332. isSuccess = ConfigurationStatus_Rejected;
  17333. }
  17334. }
  17335. if(strcmp(key, "StopTxnSampledData") == 0)
  17336. {
  17337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17338. {
  17339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17340. isSuccess = ConfigurationStatus_Accepted;
  17341. }
  17342. else
  17343. {
  17344. isSuccess = ConfigurationStatus_Rejected;
  17345. }
  17346. }
  17347. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17348. {
  17349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17350. {
  17351. check_ascii = value[0];
  17352. if( (check_ascii < 48) || (check_ascii > 57) )
  17353. {
  17354. isSuccess = ConfigurationStatus_Rejected;
  17355. }
  17356. else
  17357. {
  17358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17359. isSuccess = ConfigurationStatus_Accepted;
  17360. }
  17361. }
  17362. else
  17363. {
  17364. isSuccess = ConfigurationStatus_Rejected;
  17365. }
  17366. }
  17367. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17368. {
  17369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17370. {
  17371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17372. isSuccess = ConfigurationStatus_Accepted;
  17373. }
  17374. else
  17375. {
  17376. isSuccess = ConfigurationStatus_Rejected;
  17377. }
  17378. }
  17379. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17380. {
  17381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17382. {
  17383. check_ascii = value[0];
  17384. if( (check_ascii < 48) || (check_ascii > 57) )
  17385. {
  17386. isSuccess = ConfigurationStatus_Rejected;
  17387. }
  17388. else
  17389. {
  17390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17391. isSuccess = ConfigurationStatus_Accepted;
  17392. }
  17393. }
  17394. else
  17395. {
  17396. isSuccess = ConfigurationStatus_Rejected;
  17397. }
  17398. }
  17399. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17400. {
  17401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17402. {
  17403. check_ascii = value[0];
  17404. if( (check_ascii < 48) || (check_ascii > 57) )
  17405. {
  17406. isSuccess = ConfigurationStatus_Rejected;
  17407. }
  17408. else
  17409. {
  17410. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17412. TransactionMessageAttemptsValue = atoi(value);
  17413. isSuccess = ConfigurationStatus_Accepted;
  17414. }
  17415. }
  17416. else
  17417. {
  17418. isSuccess = ConfigurationStatus_Rejected;
  17419. }
  17420. }
  17421. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17422. {
  17423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17424. {
  17425. check_ascii = value[0];
  17426. if( (check_ascii < 48) || (check_ascii > 57) )
  17427. {
  17428. isSuccess = ConfigurationStatus_Rejected;
  17429. }
  17430. else
  17431. {
  17432. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17434. TransactionMessageRetryIntervalValue = atoi(value);
  17435. isSuccess = ConfigurationStatus_Accepted;
  17436. }
  17437. }
  17438. else
  17439. {
  17440. isSuccess = ConfigurationStatus_Rejected;
  17441. }
  17442. }
  17443. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17444. {
  17445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17446. {
  17447. strcpy(str, (const char*)value);
  17448. for(int i = 0; str[i]; i++)
  17449. {
  17450. str[i] = tolower(str[i]);
  17451. }
  17452. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17454. isSuccess = ConfigurationStatus_Accepted;
  17455. }
  17456. else
  17457. {
  17458. isSuccess = ConfigurationStatus_Rejected;
  17459. }
  17460. }
  17461. if(strcmp(key, "WebSocketPingInterval") == 0)
  17462. {
  17463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17464. {
  17465. check_ascii = value[0];
  17466. if( (check_ascii < 48) || (check_ascii > 57) )
  17467. {
  17468. isSuccess = ConfigurationStatus_Rejected;
  17469. }
  17470. else
  17471. {
  17472. if((atoi(value) == 0) || (atoi(value) >= 10))
  17473. {
  17474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17475. isSuccess = ConfigurationStatus_Accepted;
  17476. }
  17477. else
  17478. isSuccess = ConfigurationStatus_Rejected;
  17479. }
  17480. }
  17481. else
  17482. {
  17483. isSuccess = ConfigurationStatus_Rejected;
  17484. }
  17485. }
  17486. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17487. {
  17488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17489. {
  17490. strcpy(str, (const char*)value);
  17491. for(int i = 0; str[i]; i++)
  17492. {
  17493. str[i] = tolower(str[i]);
  17494. }
  17495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17496. isSuccess = ConfigurationStatus_Accepted;
  17497. }
  17498. else
  17499. {
  17500. isSuccess = ConfigurationStatus_Rejected;
  17501. }
  17502. }
  17503. if(strcmp(key, "AuthorizationKey") == 0)
  17504. {
  17505. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17506. {
  17507. strcpy(str, (const char*)value);
  17508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17509. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17510. isSuccess = ConfigurationStatus_Accepted;
  17511. }
  17512. else
  17513. {
  17514. isSuccess = ConfigurationStatus_Rejected;
  17515. }
  17516. }
  17517. if(strcmp(key, "SecurityProfile") == 0)
  17518. {
  17519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17520. {
  17521. check_ascii = value[0];
  17522. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17523. {
  17524. isSuccess = ConfigurationStatus_Rejected;
  17525. }
  17526. else if(check_ascii == 0x33)
  17527. {
  17528. isSuccess = NotSupported;
  17529. }
  17530. else
  17531. {
  17532. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17533. {
  17534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17535. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17536. isSuccess = ConfigurationStatus_Accepted;
  17537. }
  17538. else
  17539. isSuccess = ConfigurationStatus_Rejected;
  17540. }
  17541. }
  17542. else
  17543. {
  17544. isSuccess = ConfigurationStatus_Rejected;
  17545. }
  17546. }
  17547. if(strcmp(key, "DefaultPrice") == 0)
  17548. {
  17549. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17550. {
  17551. strcpy(str, (const char*)value);
  17552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17553. isSuccess = ConfigurationStatus_Accepted;
  17554. }
  17555. else
  17556. {
  17557. isSuccess = ConfigurationStatus_Rejected;
  17558. }
  17559. }
  17560. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17561. {
  17562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17563. {
  17564. strcpy(str, (const char*)value);
  17565. for(int i = 0; str[i]; i++)
  17566. {
  17567. str[i] = tolower(str[i]);
  17568. }
  17569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17570. isSuccess = ConfigurationStatus_Accepted;
  17571. }
  17572. else
  17573. {
  17574. isSuccess = ConfigurationStatus_Rejected;
  17575. }
  17576. }
  17577. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17578. {
  17579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17580. {
  17581. strcpy(str, (const char*)value);
  17582. for(int i = 0; str[i]; i++)
  17583. {
  17584. str[i] = tolower(str[i]);
  17585. }
  17586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17587. isSuccess = ConfigurationStatus_Accepted;
  17588. }
  17589. else
  17590. {
  17591. isSuccess = ConfigurationStatus_Rejected;
  17592. }
  17593. }
  17594. if(strcmp(key, "TimeOffset") == 0)
  17595. {
  17596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17597. {
  17598. strcpy(str, (const char*)value);
  17599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17600. isSuccess = ConfigurationStatus_Accepted;
  17601. }
  17602. else
  17603. {
  17604. isSuccess = ConfigurationStatus_Rejected;
  17605. }
  17606. }
  17607. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17608. {
  17609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17610. {
  17611. strcpy(str, (const char*)value);
  17612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17613. isSuccess = ConfigurationStatus_Accepted;
  17614. }
  17615. else
  17616. {
  17617. isSuccess = ConfigurationStatus_Rejected;
  17618. }
  17619. }
  17620. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17621. {
  17622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17623. {
  17624. strcpy(str, (const char*)value);
  17625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17626. isSuccess = ConfigurationStatus_Accepted;
  17627. }
  17628. else
  17629. {
  17630. isSuccess = ConfigurationStatus_Rejected;
  17631. }
  17632. }
  17633. if(strcmp(key, "SystemUptimeSec") == 0)
  17634. {
  17635. isSuccess = NotSupported;
  17636. }
  17637. if(strcmp(key, "FreeVend") == 0)
  17638. {
  17639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17640. {
  17641. strcpy(str, (const char*)value);
  17642. for(int i = 0; str[i]; i++)
  17643. {
  17644. str[i] = tolower(str[i]);
  17645. }
  17646. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17648. isSuccess = ConfigurationStatus_Accepted;
  17649. }
  17650. else
  17651. {
  17652. isSuccess = ConfigurationStatus_Rejected;
  17653. }
  17654. }
  17655. if(strcmp(key, "FreeVendIdtag") == 0)
  17656. {
  17657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17658. {
  17659. strcpy(str, (const char*)value);
  17660. if(strlen(str) <= 20)
  17661. {
  17662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17663. isSuccess = ConfigurationStatus_Accepted;
  17664. }
  17665. else
  17666. {
  17667. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17668. isSuccess = ConfigurationStatus_Rejected;
  17669. }
  17670. }
  17671. else
  17672. {
  17673. isSuccess = ConfigurationStatus_Rejected;
  17674. }
  17675. }
  17676. if(strcmp(key, "OcppServer") == 0)
  17677. {
  17678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17679. {
  17680. strcpy(str, (const char*)value);
  17681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17682. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17683. isSuccess = ConfigurationStatus_Accepted;
  17684. }
  17685. else
  17686. {
  17687. isSuccess = ConfigurationStatus_Rejected;
  17688. }
  17689. }
  17690. if(strcmp(key, "MaintainServer") == 0)
  17691. {
  17692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17693. {
  17694. strcpy(str, (const char*)value);
  17695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17696. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17697. isSuccess = ConfigurationStatus_Accepted;
  17698. }
  17699. else
  17700. {
  17701. isSuccess = ConfigurationStatus_Rejected;
  17702. }
  17703. }
  17704. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17705. {
  17706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17707. {
  17708. strcpy(str, (const char*)value);
  17709. for(int i = 0; str[i]; i++)
  17710. {
  17711. str[i] = tolower(str[i]);
  17712. }
  17713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17714. isSuccess = ConfigurationStatus_Accepted;
  17715. }
  17716. else
  17717. {
  17718. isSuccess = ConfigurationStatus_Rejected;
  17719. }
  17720. }
  17721. if(strcmp(key, "StatusNotificationInterval") == 0)
  17722. {
  17723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17724. {
  17725. check_ascii = value[0];
  17726. if( (check_ascii < 48) || (check_ascii > 57) )
  17727. {
  17728. isSuccess = ConfigurationStatus_Rejected;
  17729. }
  17730. else
  17731. {
  17732. if((atoi(value) == 0) || (atoi(value) >= 10))
  17733. {
  17734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17735. isSuccess = ConfigurationStatus_Accepted;
  17736. }
  17737. else
  17738. isSuccess = ConfigurationStatus_Rejected;
  17739. }
  17740. }
  17741. else
  17742. {
  17743. isSuccess = ConfigurationStatus_Rejected;
  17744. }
  17745. }
  17746. if(strcmp(key, "PreAuthAmount") == 0)
  17747. {
  17748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17749. {
  17750. check_ascii = value[0];
  17751. if( (check_ascii < 48) || (check_ascii > 57) )
  17752. {
  17753. isSuccess = ConfigurationStatus_Rejected;
  17754. }
  17755. else
  17756. {
  17757. if(atof(value) >= 0)
  17758. {
  17759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17760. isSuccess = ConfigurationStatus_Accepted;
  17761. }
  17762. else
  17763. isSuccess = ConfigurationStatus_Rejected;
  17764. }
  17765. }
  17766. else
  17767. {
  17768. isSuccess = ConfigurationStatus_Rejected;
  17769. }
  17770. }
  17771. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17772. {
  17773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17774. {
  17775. check_ascii = value[0];
  17776. if( (check_ascii < 48) || (check_ascii > 57) )
  17777. {
  17778. isSuccess = ConfigurationStatus_Rejected;
  17779. }
  17780. else
  17781. {
  17782. if(atoi(value) >= 0)
  17783. {
  17784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17785. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17786. isSuccess = ConfigurationStatus_Accepted;
  17787. }
  17788. else
  17789. isSuccess = ConfigurationStatus_Rejected;
  17790. }
  17791. }
  17792. else
  17793. {
  17794. isSuccess = ConfigurationStatus_Rejected;
  17795. }
  17796. }
  17797. if(strcmp(key, "PowerSharingServerIP") == 0)
  17798. {
  17799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17800. {
  17801. strcpy(str, (const char*)value);
  17802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17803. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17804. isSuccess = ConfigurationStatus_Accepted;
  17805. }
  17806. else
  17807. {
  17808. isSuccess = ConfigurationStatus_Rejected;
  17809. }
  17810. }
  17811. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17812. {
  17813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17814. {
  17815. strcpy(str, (const char*)value);
  17816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17817. isSuccess = ConfigurationStatus_Accepted;
  17818. }
  17819. else
  17820. {
  17821. isSuccess = ConfigurationStatus_Rejected;
  17822. }
  17823. }
  17824. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17825. {
  17826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17827. {
  17828. if(atoi(value) > modelnameInfo.ratedPower)
  17829. {
  17830. isSuccess = ConfigurationStatus_Rejected;
  17831. }
  17832. else{
  17833. strcpy(str, (const char*)value);
  17834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17835. isSuccess = ConfigurationStatus_Accepted;
  17836. }
  17837. }
  17838. else
  17839. {
  17840. isSuccess = ConfigurationStatus_Rejected;
  17841. }
  17842. }
  17843. #if 0
  17844. //For OCPP Test Case
  17845. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17846. {
  17847. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17848. {
  17849. strcpy(str, (const char*)value);
  17850. for(int i = 0; str[i]; i++)
  17851. {
  17852. str[i] = tolower(str[i]);
  17853. }
  17854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17855. isSuccess = ConfigurationStatus_Accepted;
  17856. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17857. }
  17858. else
  17859. {
  17860. isSuccess = ConfigurationStatus_Rejected;
  17861. }
  17862. }
  17863. #endif
  17864. #if 1
  17865. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17866. {
  17867. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17868. {
  17869. strcpy(str, (const char*)value);
  17870. for(int i = 0; str[i]; i++)
  17871. {
  17872. str[i] = tolower(str[i]);
  17873. }
  17874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17875. isSuccess = ConfigurationStatus_Accepted;
  17876. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17877. }
  17878. else
  17879. {
  17880. isSuccess = ConfigurationStatus_Rejected;
  17881. }
  17882. }
  17883. #endif
  17884. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17885. {
  17886. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17887. {
  17888. check_ascii = value[0];
  17889. if( (check_ascii < 48) || (check_ascii > 57) )
  17890. {
  17891. isSuccess = ConfigurationStatus_Rejected;
  17892. }
  17893. else
  17894. {
  17895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17896. isSuccess = ConfigurationStatus_Accepted;
  17897. }
  17898. }
  17899. else
  17900. {
  17901. isSuccess = ConfigurationStatus_Rejected;
  17902. }
  17903. }
  17904. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17905. {
  17906. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17907. {
  17908. check_ascii = value[0];
  17909. if( (check_ascii < 48) || (check_ascii > 57) )
  17910. {
  17911. isSuccess = ConfigurationStatus_Rejected;
  17912. }
  17913. else
  17914. {
  17915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17916. isSuccess = ConfigurationStatus_Accepted;
  17917. }
  17918. }
  17919. else
  17920. {
  17921. isSuccess = ConfigurationStatus_Rejected;
  17922. }
  17923. }
  17924. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17925. {
  17926. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17927. {
  17928. strcpy(str, (const char*)value);
  17929. for(int i = 0; str[i]; i++)
  17930. {
  17931. str[i] = tolower(str[i]);
  17932. }
  17933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17934. isSuccess = ConfigurationStatus_Accepted;
  17935. }
  17936. else
  17937. {
  17938. isSuccess = ConfigurationStatus_Rejected;
  17939. }
  17940. }
  17941. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17942. {
  17943. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17944. {
  17945. check_ascii = value[0];
  17946. if( (check_ascii < 48) || (check_ascii > 57) )
  17947. {
  17948. isSuccess = ConfigurationStatus_Rejected;
  17949. }
  17950. else
  17951. {
  17952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17953. isSuccess = ConfigurationStatus_Accepted;
  17954. }
  17955. }
  17956. else
  17957. {
  17958. isSuccess = ConfigurationStatus_Rejected;
  17959. }
  17960. }
  17961. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17962. {
  17963. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17964. {
  17965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17966. isSuccess = ConfigurationStatus_Accepted;
  17967. }
  17968. else
  17969. {
  17970. isSuccess = ConfigurationStatus_Rejected;
  17971. }
  17972. }
  17973. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17974. {
  17975. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17976. {
  17977. check_ascii = value[0];
  17978. if( (check_ascii < 48) || (check_ascii > 57) )
  17979. {
  17980. isSuccess = ConfigurationStatus_Rejected;
  17981. }
  17982. else
  17983. {
  17984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17985. isSuccess = ConfigurationStatus_Accepted;
  17986. }
  17987. }
  17988. else
  17989. {
  17990. isSuccess = ConfigurationStatus_Rejected;
  17991. }
  17992. }
  17993. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17994. {
  17995. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17996. {
  17997. strcpy(str, (const char*)value);
  17998. for(int i = 0; str[i]; i++)
  17999. {
  18000. str[i] = tolower(str[i]);
  18001. }
  18002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18003. isSuccess = ConfigurationStatus_Accepted;
  18004. }
  18005. else
  18006. {
  18007. isSuccess = ConfigurationStatus_Rejected;
  18008. }
  18009. }
  18010. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18011. {
  18012. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18013. {
  18014. check_ascii = value[0];
  18015. if( (check_ascii < 48) || (check_ascii > 57) )
  18016. {
  18017. isSuccess = ConfigurationStatus_Rejected;
  18018. }
  18019. else
  18020. {
  18021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18022. isSuccess = ConfigurationStatus_Accepted;
  18023. }
  18024. }
  18025. else
  18026. {
  18027. isSuccess = ConfigurationStatus_Rejected;
  18028. }
  18029. }
  18030. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18031. return isSuccess;
  18032. }
  18033. int TransactionMessageAttemptsGet(void)
  18034. {
  18035. return TransactionMessageAttemptsValue;
  18036. }
  18037. int FirstHeartBeatResponse(void)
  18038. {
  18039. return FirstHeartBeat;
  18040. }
  18041. int TransactionMessageRetryIntervalGet(void)
  18042. {
  18043. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18044. }
  18045. int ReadHttpStatus(int sock)
  18046. {
  18047. //char c;
  18048. char buff[1024]="",*ptr=buff+1;
  18049. int bytes_received, status;
  18050. DEBUG_INFO("Begin Response ..\n");
  18051. while((bytes_received = recv(sock, ptr, 1, 0))){
  18052. if(bytes_received==-1){
  18053. perror("ReadHttpStatus");
  18054. exit(1);
  18055. }
  18056. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18057. ptr++;
  18058. }
  18059. *ptr=0;
  18060. ptr=buff+1;
  18061. sscanf(ptr,"%*s %d ", &status);
  18062. DEBUG_INFO("%s\n",ptr);
  18063. DEBUG_INFO("status=%d\n",status);
  18064. DEBUG_INFO("End Response ..\n");
  18065. return (bytes_received>0)?status:0;
  18066. }
  18067. //the only filed that it parsed is 'Content-Length'
  18068. int ParseHeader(int sock)
  18069. {
  18070. //char c;
  18071. char buff[1024]="",*ptr=buff+4;
  18072. int bytes_received;
  18073. DEBUG_INFO("Begin HEADER ..\n");
  18074. while((bytes_received = recv(sock, ptr, 1, 0))){
  18075. if(bytes_received==-1){
  18076. perror("Parse Header");
  18077. exit(1);
  18078. }
  18079. if(
  18080. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18081. (ptr[-1]=='\r') && (*ptr=='\n' )
  18082. ) break;
  18083. ptr++;
  18084. }
  18085. *ptr=0;
  18086. ptr=buff+4;
  18087. //printf("%s",ptr);
  18088. if(bytes_received){
  18089. ptr=strstr(ptr,"Content-Length:");
  18090. if(ptr){
  18091. sscanf(ptr,"%*s %d",&bytes_received);
  18092. }else
  18093. bytes_received=-1; //unknown size
  18094. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18095. }
  18096. DEBUG_INFO("End HEADER ..\n");
  18097. return bytes_received ;
  18098. }
  18099. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18100. {
  18101. int result = TRUE;
  18102. char rmFileCmd[100]={0};
  18103. char FilePath[100]={0};
  18104. char ftpbuf[200];
  18105. int systemresult;
  18106. sprintf(FilePath,"/mnt/%s",filename);
  18107. system("ping 8.8.8.8 &");
  18108. if((access(FilePath,F_OK))!=-1)
  18109. {
  18110. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18111. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18112. system(rmFileCmd);
  18113. }
  18114. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18115. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18116. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18117. systemresult = system(ftpbuf);
  18118. if(systemresult != 0)
  18119. {
  18120. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18121. result = FALSE;
  18122. }
  18123. system("pkill ping");
  18124. return result;
  18125. }
  18126. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18127. {
  18128. int result = TRUE;
  18129. char rmFileCmd[100]={0};
  18130. char FilePath[100]={0};
  18131. char ftpbuf[200];
  18132. int systemresult;
  18133. sprintf(FilePath,"/mnt/%s",filename);
  18134. system("ping 8.8.8.8 &");
  18135. if((access(FilePath,F_OK))!=-1)
  18136. {
  18137. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18138. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18139. system(rmFileCmd);
  18140. }
  18141. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18142. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18143. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18144. systemresult = system(ftpbuf);
  18145. if(systemresult != 0)
  18146. {
  18147. DEBUG_WARN("scp error!\n");
  18148. result = FALSE;
  18149. }
  18150. system("pkill ping");
  18151. return result;
  18152. }
  18153. int ftpDownLoadFile(char *location, char *user, char *password, int port, 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",filename, url);
  18170. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18171. systemresult = system(ftpbuf);
  18172. if(systemresult != 0)
  18173. {
  18174. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18175. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18176. systemresult = system(ftpbuf);
  18177. if(systemresult != 0)
  18178. {
  18179. DEBUG_WARN("FTP download fail!\n");
  18180. result = FALSE;
  18181. }
  18182. }
  18183. system("pkill ping");
  18184. return result;
  18185. }
  18186. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18187. {
  18188. char rmFileCmd[100]={0};
  18189. char FilePath[100]={0};
  18190. char buf[512];
  18191. int systemresult = 0;
  18192. //DEBUG_INFO("filename=%s\n",filename);
  18193. //DEBUG_INFO("url=%s\n",url);
  18194. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18195. if((access(FilePath,F_OK))!=-1)
  18196. {
  18197. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18198. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18199. system(rmFileCmd);
  18200. }
  18201. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18202. if(fp == NULL)
  18203. {
  18204. DEBUG_INFO("log is NULL\n");
  18205. return FALSE;
  18206. }
  18207. else
  18208. {
  18209. fprintf(fp, "%s\n", url);
  18210. fprintf(fp, "%s\n", filename);
  18211. fclose(fp);
  18212. }
  18213. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18214. if(phpFP == NULL)
  18215. {
  18216. DEBUG_INFO("PHP upload fail.\n");
  18217. return FALSE;
  18218. }
  18219. else
  18220. {
  18221. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18222. {
  18223. if(strstr(buf, "result") != NULL)
  18224. {
  18225. sscanf(buf, "result: %d", &systemresult);
  18226. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18227. }
  18228. }
  18229. pclose(phpFP);
  18230. }
  18231. if(systemresult != 1)
  18232. {
  18233. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18234. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18235. if(phpFP == NULL)
  18236. {
  18237. DEBUG_WARN("PHP PUT upload fail.\n");
  18238. return FALSE;
  18239. }
  18240. else
  18241. {
  18242. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18243. {
  18244. if(strstr(buf, "result") != NULL)
  18245. {
  18246. sscanf(buf, "result: %d", &systemresult);
  18247. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18248. }
  18249. }
  18250. pclose(phpFP);
  18251. }
  18252. }
  18253. if(systemresult != 1)
  18254. {
  18255. DEBUG_WARN("PHP PUT upload fail.\n");
  18256. return FALSE;
  18257. }
  18258. return TRUE;
  18259. }
  18260. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18261. {
  18262. int result = FALSE;
  18263. char ftpbuf[200];
  18264. int systemresult;
  18265. /*
  18266. // Domaind name transfer to IP address
  18267. struct hostent* server;
  18268. char *IPbuffer;
  18269. server = gethostbyname(location);
  18270. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18271. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18272. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18273. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18274. systemresult = system(ftpbuf);
  18275. if(systemresult != 0)
  18276. {
  18277. DEBUG_INFO("ftpput error!\n");
  18278. }
  18279. else
  18280. {
  18281. result = TRUE;
  18282. DEBUG_INFO("ftpput OK!\n");
  18283. }
  18284. return result;
  18285. }
  18286. int GetOcppServerURL()
  18287. {
  18288. int result = FALSE;
  18289. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18290. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18291. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18292. struct yuarel url;
  18293. char urlStr[512];
  18294. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18295. {
  18296. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18297. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18298. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18299. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18300. if(yuarel_parse(&url, urlStr) != -1)
  18301. {
  18302. sprintf(OcppProtocol, "%s", url.scheme);
  18303. sprintf(OcppHost, "%s", url.host);
  18304. if(url.path == NULL)
  18305. OcppTempPath[0] = '\0';
  18306. else
  18307. {
  18308. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18309. {
  18310. sprintf(OcppTempPath, "%s/", url.path);
  18311. }
  18312. else
  18313. {
  18314. sprintf(OcppTempPath, "%s", url.path);
  18315. }
  18316. }
  18317. if(url.port == 0)
  18318. {
  18319. if(strcmp(OcppProtocol, "wss") == 0)
  18320. OcppPort = 443;
  18321. else
  18322. OcppPort = 80;
  18323. }
  18324. else
  18325. OcppPort = url.port;
  18326. result = TRUE;
  18327. }
  18328. }
  18329. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18330. {
  18331. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18332. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18333. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18334. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18335. if(yuarel_parse(&url, urlStr) != -1)
  18336. {
  18337. sprintf(OcppProtocol, "%s", url.scheme);
  18338. sprintf(OcppHost, "%s", url.host);
  18339. if(url.path == NULL)
  18340. OcppTempPath[0] = '\0';
  18341. else
  18342. sprintf(OcppTempPath, "%s", url.path);
  18343. if(url.port == 0)
  18344. {
  18345. if(strcmp(OcppProtocol, "wss") == 0)
  18346. OcppPort = 443;
  18347. else
  18348. OcppPort = 80;
  18349. }
  18350. else
  18351. OcppPort = url.port;
  18352. result = TRUE;
  18353. }
  18354. }
  18355. else
  18356. {
  18357. strcpy(OcppHost,"");
  18358. }
  18359. return result;
  18360. }
  18361. int GetOcppPath()
  18362. {
  18363. int result = FALSE;
  18364. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18365. {
  18366. if(OcppTempPath == NULL)
  18367. {
  18368. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18369. }
  18370. else
  18371. {
  18372. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18373. }
  18374. result = TRUE;
  18375. goto End;
  18376. }
  18377. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18378. {
  18379. if(OcppTempPath == NULL)
  18380. {
  18381. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18382. }
  18383. else
  18384. {
  18385. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18386. }
  18387. result = TRUE;
  18388. goto End;
  18389. }
  18390. else
  18391. {
  18392. strcpy(OcppPath,"");
  18393. }
  18394. End:
  18395. return result;
  18396. }
  18397. int GetOcppPort()
  18398. {
  18399. return OcppPort;
  18400. }
  18401. int GetOcppConnStatus(void)
  18402. {
  18403. return ShmOCPP16Data->OcppConnStatus;
  18404. }
  18405. void SetOcppConnStatus(uint8_t status)
  18406. {
  18407. ShmOCPP16Data->OcppConnStatus = status;
  18408. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18409. }
  18410. int GetHeartBeatWithNOResponse(void)
  18411. {
  18412. return HeartBeatWithNOResponse;
  18413. }
  18414. void SetHeartBeatWithNOResponse(void)
  18415. {
  18416. HeartBeatWithNOResponse = 0;
  18417. }
  18418. void GetStartTransactionIdTag(int gun_index)
  18419. {
  18420. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18421. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18422. }
  18423. int GetStartTransactionId(int gun_index)
  18424. {
  18425. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18426. }
  18427. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18428. {
  18429. char ch;
  18430. FILE *fptr1;
  18431. int temptransactionId;
  18432. char str[100]={0};
  18433. temptransactionId = 0;
  18434. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18435. {
  18436. DEBUG_INFO("IdTag is empty.\n");
  18437. return temptransactionId;
  18438. }
  18439. /*------ Read the file ----------------*/
  18440. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18441. if (!fptr1)
  18442. {
  18443. DEBUG_INFO("QueueTransactionId file open error.\n");
  18444. //printf(" File not found or unable to open the input file!!\n");
  18445. return temptransactionId;
  18446. }
  18447. ch=fgetc(fptr1);
  18448. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18449. rewind(fptr1);
  18450. if(ch!=EOF)
  18451. {
  18452. // printf("%c",ch);
  18453. while (fgets(str, 100, fptr1) != NULL)
  18454. {
  18455. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18456. if(str[0]=='\0')
  18457. {
  18458. break;
  18459. }
  18460. char *revbuf[8] = {0}; // Variable store string split
  18461. int num = 0;// Quantity after string split
  18462. DEBUG_INFO("Transaction queue data= %s\n", str);
  18463. splitstring(str,",",revbuf,&num); // String split
  18464. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18465. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18466. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18467. DEBUG_INFO("------------------------------\n");
  18468. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18469. {
  18470. if(isStopTransaction)
  18471. {
  18472. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18473. {
  18474. temptransactionId = atoi(revbuf[2]);
  18475. //break;
  18476. }
  18477. }
  18478. else
  18479. {
  18480. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18481. {
  18482. temptransactionId = atoi(revbuf[2]);
  18483. //break;
  18484. }
  18485. }
  18486. }
  18487. }
  18488. }
  18489. else
  18490. DEBUG_INFO("EOF\n");
  18491. fclose(fptr1);
  18492. /*------- End of reading ---------------*/
  18493. return temptransactionId;
  18494. }
  18495. void SetTransactionIdZero(int transactionId)
  18496. {
  18497. char ch;
  18498. FILE *fptr1, *fptr2;
  18499. int temptransactionId = 0;
  18500. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18501. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18502. if (!fptr1)
  18503. {
  18504. //printf(" File not found or unable to open the input file!!\n");
  18505. return ;
  18506. }
  18507. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18508. if (!fptr2)
  18509. {
  18510. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18511. fclose(fptr1);
  18512. return ;
  18513. }
  18514. ch=fgetc(fptr1);
  18515. rewind(fptr1);
  18516. if(ch!=EOF)
  18517. {
  18518. // copy all contents to the temporary file except the specific line
  18519. while (fgets(str, 100, fptr1) != NULL)
  18520. {
  18521. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18522. if(str[0]=='\0')
  18523. {
  18524. break;
  18525. }
  18526. char *revbuf[8] = {0};
  18527. int num = 0;
  18528. strcpy(strtemp, str);
  18529. splitstring(str,",",revbuf,&num);
  18530. if(revbuf[2][0] != '\0')
  18531. {
  18532. temptransactionId = atoi(revbuf[2]);
  18533. if(transactionId != temptransactionId)
  18534. {
  18535. fprintf(fptr2, "%s\n", strtemp);
  18536. }
  18537. }
  18538. }
  18539. }
  18540. fclose(fptr1);
  18541. fclose(fptr2);
  18542. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18543. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18544. /*------ Read the file ----------------*/
  18545. }
  18546. int InternetDisconnect(void)
  18547. {
  18548. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18549. }
  18550. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18551. void storeTempStopTransaction(int gun_index)
  18552. {
  18553. char guid[37]={0};
  18554. int tempIndex = 0;
  18555. char TempStopTransaction[256];
  18556. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18557. DEBUG_INFO("storeTempStopTransaction...\n");
  18558. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18559. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18560. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18561. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18562. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18563. {
  18564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18565. {
  18566. tempIndex = ((gun_index==2) ? 1: 0);
  18567. }
  18568. else
  18569. {
  18570. tempIndex = gun_index;
  18571. }
  18572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18573. {
  18574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18575. {
  18576. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18577. }
  18578. }// END OF CHAdeMO_QUANTITY
  18579. }
  18580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18581. {
  18582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18583. {
  18584. tempIndex = ((gun_index==2) ? 1: 0);
  18585. }
  18586. else
  18587. {
  18588. tempIndex = gun_index;
  18589. }
  18590. for (int index = 0; index < CCS_QUANTITY; index++)
  18591. {
  18592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18593. {
  18594. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18595. }
  18596. }// END OF CCS_QUANTITY
  18597. }
  18598. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18599. {
  18600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18601. {
  18602. tempIndex = ((gun_index==2) ? 1: 0);
  18603. }
  18604. else
  18605. {
  18606. tempIndex = gun_index;
  18607. }
  18608. for (int index = 0; index < GB_QUANTITY; index++)
  18609. {
  18610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18611. {
  18612. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18613. }
  18614. }// END OF GB_QUANTITY
  18615. }
  18616. else if(gunType[gun_index] == GUN_TYPE_DO)
  18617. {
  18618. tempIndex = gun_index;
  18619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18620. {
  18621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18622. {
  18623. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18624. }
  18625. }
  18626. }
  18627. else
  18628. {
  18629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18630. {
  18631. tempIndex = 2;
  18632. }
  18633. else
  18634. {
  18635. tempIndex = gun_index;
  18636. }
  18637. for (int index = 0; index < AC_QUANTITY; index++)
  18638. {
  18639. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18640. {
  18641. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18642. }
  18643. }// END OF AC_QUANTITY
  18644. }
  18645. //Stop Transaction Time
  18646. struct timeval tmnow;
  18647. struct tm *tm;
  18648. char buf[28];//, usec_buf[6];
  18649. gettimeofday(&tmnow, NULL);
  18650. time_t t;
  18651. t = time(NULL);
  18652. /*UTC time and date*/
  18653. tm = gmtime(&t);
  18654. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18656. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18658. random_uuid(guid);
  18659. /***********************************transactionData******************************************************/
  18660. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18662. //=================================
  18663. //1. Transaction_Begin
  18664. //=================================
  18665. //============================== Energy.Active.Import.Interval ===========================================
  18666. //=================================
  18667. //2. Transaction_End
  18668. //=================================
  18669. //2.1====================================== Current.Import L1 ==============================================
  18670. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18671. {
  18672. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18673. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18674. {
  18675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18676. {
  18677. tempIndex = ((gun_index==2) ? 1: 0);
  18678. }
  18679. else
  18680. {
  18681. tempIndex = gun_index;
  18682. }
  18683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18684. {
  18685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18686. {
  18687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18688. }
  18689. }// End of for CHAdeMO_QUANTITY
  18690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18691. }
  18692. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18693. {
  18694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18695. {
  18696. tempIndex = ((gun_index==2) ? 1: 0);
  18697. }
  18698. else
  18699. {
  18700. tempIndex = gun_index;
  18701. }
  18702. for (int index = 0; index < CCS_QUANTITY; index++)
  18703. {
  18704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18705. {
  18706. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18707. }
  18708. }// End of for CCS_QUANTITY
  18709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18710. }
  18711. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18712. {
  18713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18714. {
  18715. tempIndex = ((gun_index==2) ? 1: 0);
  18716. }
  18717. else
  18718. {
  18719. tempIndex = gun_index;
  18720. }
  18721. for (int index = 0; index < GB_QUANTITY; index++)
  18722. {
  18723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18724. {
  18725. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18726. }
  18727. }// End of for GB_QUANTITY
  18728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18729. }
  18730. else if(gunType[gun_index] == GUN_TYPE_DO)
  18731. {
  18732. tempIndex = gun_index;
  18733. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18734. {
  18735. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18736. {
  18737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18738. }
  18739. }
  18740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18741. }
  18742. else
  18743. {
  18744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18745. {
  18746. tempIndex = 2;
  18747. }
  18748. else
  18749. {
  18750. tempIndex = gun_index;
  18751. }
  18752. for (int index = 0; index < AC_QUANTITY; index++)
  18753. {
  18754. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18755. {
  18756. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18757. }
  18758. }// End of for AC_QUANTITY
  18759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18760. }
  18761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18764. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18767. }
  18768. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18769. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18770. {
  18771. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18773. {
  18774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18775. {
  18776. tempIndex = ((gun_index==2) ? 1: 0);
  18777. }
  18778. else
  18779. {
  18780. tempIndex = gun_index;
  18781. }
  18782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18783. {
  18784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18785. {
  18786. 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
  18787. }
  18788. }// END OF CHAdeMO_QUANTITY
  18789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18790. }
  18791. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18792. {
  18793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18794. {
  18795. tempIndex = ((gun_index==2) ? 1: 0);
  18796. }
  18797. else
  18798. {
  18799. tempIndex = gun_index;
  18800. }
  18801. for (int index = 0; index < CCS_QUANTITY; index++)
  18802. {
  18803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18804. {
  18805. 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
  18806. }
  18807. }// END OF CCS_QUANTITY
  18808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18809. }
  18810. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18811. {
  18812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18813. {
  18814. tempIndex = ((gun_index==2) ? 1: 0);
  18815. }
  18816. else
  18817. {
  18818. tempIndex = gun_index;
  18819. }
  18820. for (int index = 0; index < GB_QUANTITY; index++)
  18821. {
  18822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18823. {
  18824. 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
  18825. }
  18826. }// END OF GB_QUANTITY
  18827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18828. }
  18829. else if(gunType[gun_index] == GUN_TYPE_DO)
  18830. {
  18831. tempIndex = gun_index;
  18832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18833. {
  18834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18835. {
  18836. 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
  18837. }
  18838. }
  18839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18840. }
  18841. else
  18842. {
  18843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18844. {
  18845. tempIndex = 2;
  18846. }
  18847. else
  18848. {
  18849. tempIndex = gun_index;
  18850. }
  18851. for (int index = 0; index < AC_QUANTITY; index++)
  18852. {
  18853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18854. {
  18855. 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
  18856. }
  18857. }// END OF AC_QUANTITY
  18858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18859. }
  18860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18863. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18866. }
  18867. //2.3====================================== Power.Active.Import =========================================
  18868. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18869. {
  18870. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18871. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18872. {
  18873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18874. {
  18875. tempIndex = ((gun_index==2) ? 1: 0);
  18876. }
  18877. else
  18878. {
  18879. tempIndex = gun_index;
  18880. }
  18881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18882. {
  18883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18884. {
  18885. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18886. }
  18887. } // End for CHAdeMO_QUANTITY
  18888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18889. }
  18890. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18891. {
  18892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18893. {
  18894. tempIndex = ((gun_index==2) ? 1: 0);
  18895. }
  18896. else
  18897. {
  18898. tempIndex = gun_index;
  18899. }
  18900. for (int index = 0; index < CCS_QUANTITY; index++)
  18901. {
  18902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18903. {
  18904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18905. }
  18906. } // END for CCS_QUANTITY
  18907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18908. }
  18909. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18910. {
  18911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18912. {
  18913. tempIndex = ((gun_index==2) ? 1: 0);
  18914. }
  18915. else
  18916. {
  18917. tempIndex = gun_index;
  18918. }
  18919. for (int index = 0; index < GB_QUANTITY; index++)
  18920. {
  18921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18922. {
  18923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18924. }
  18925. }// END for GB_QUANTITY
  18926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18927. }
  18928. else if(gunType[gun_index] == GUN_TYPE_DO)
  18929. {
  18930. tempIndex = gun_index;
  18931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18932. {
  18933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18934. {
  18935. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18936. }
  18937. }
  18938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18939. }
  18940. else
  18941. {
  18942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18943. {
  18944. tempIndex = 2;
  18945. }
  18946. else
  18947. {
  18948. tempIndex = gun_index;
  18949. }
  18950. for (int index = 0; index < AC_QUANTITY; index++)
  18951. {
  18952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18953. {
  18954. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18955. }
  18956. } // END for AC_QUANTITY
  18957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18958. }
  18959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18962. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18965. }
  18966. //2.4====================================== Voltage L1 ====================================================
  18967. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18968. {
  18969. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18971. {
  18972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18973. {
  18974. tempIndex = ((gun_index==2) ? 1: 0);
  18975. }
  18976. else
  18977. {
  18978. tempIndex = gun_index;
  18979. }
  18980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18981. {
  18982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18983. {
  18984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18985. }
  18986. } // END OF FOR CHAdeMO_QUANTITY
  18987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18988. }
  18989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18990. {
  18991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18992. {
  18993. tempIndex = ((gun_index==2) ? 1: 0);
  18994. }
  18995. else
  18996. {
  18997. tempIndex = gun_index;
  18998. }
  18999. for (int index = 0; index < CCS_QUANTITY; index++)
  19000. {
  19001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19002. {
  19003. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19004. }
  19005. } // END OF FOR CCS_QUANTITY
  19006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19007. }
  19008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19009. {
  19010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19011. {
  19012. tempIndex = ((gun_index==2) ? 1: 0);
  19013. }
  19014. else
  19015. {
  19016. tempIndex = gun_index;
  19017. }
  19018. for (int index = 0; index < GB_QUANTITY; index++)
  19019. {
  19020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19021. {
  19022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19023. }
  19024. } // END OF FOR GB_QUANTITY
  19025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19026. }
  19027. else if(gunType[gun_index] == GUN_TYPE_DO)
  19028. {
  19029. tempIndex = gun_index;
  19030. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19031. {
  19032. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19033. {
  19034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19035. }
  19036. }
  19037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19038. }
  19039. else
  19040. {
  19041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19042. {
  19043. tempIndex = 2;
  19044. }
  19045. else
  19046. {
  19047. tempIndex = gun_index;
  19048. }
  19049. for (int index = 0; index < AC_QUANTITY; index++)
  19050. {
  19051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19052. {
  19053. 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
  19054. }
  19055. } // END OF FOR AC_QUANTITY
  19056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19057. }
  19058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19061. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19064. }
  19065. //2.5============================================== End SoC =========================================================
  19066. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19067. {
  19068. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19069. 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))
  19070. {
  19071. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19072. {
  19073. tempIndex = ((gun_index==2) ? 1: 0);
  19074. }
  19075. else
  19076. {
  19077. tempIndex = gun_index;
  19078. }
  19079. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19080. {
  19081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19082. {
  19083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19084. {
  19085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19086. }
  19087. }
  19088. }
  19089. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19090. {
  19091. for (int index = 0; index < CCS_QUANTITY; index++)
  19092. {
  19093. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19094. {
  19095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19096. }
  19097. }
  19098. }
  19099. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19100. {
  19101. for (int index = 0; index < GB_QUANTITY; index++)
  19102. {
  19103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19104. {
  19105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19106. }
  19107. }
  19108. }
  19109. else if(gunType[gun_index] == GUN_TYPE_DO)
  19110. {
  19111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19112. {
  19113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19114. {
  19115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19116. }
  19117. }
  19118. }
  19119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19125. } // END FOR DC CASE
  19126. }
  19127. //2.6====================================== Current.Import L2 ==============================================
  19128. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19129. {
  19130. // AC 3 phase L2 current
  19131. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19132. {
  19133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19134. {
  19135. tempIndex = 2;
  19136. }
  19137. else
  19138. {
  19139. tempIndex = gun_index;
  19140. }
  19141. for (int index = 0; index < AC_QUANTITY; index++)
  19142. {
  19143. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19144. {
  19145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19146. }
  19147. }// End of for AC_QUANTITY
  19148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19149. }
  19150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19155. }
  19156. //2.7====================================== Current.Import L3 ==============================================
  19157. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19158. {
  19159. // AC 3 phase L3 current
  19160. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19161. {
  19162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19163. {
  19164. tempIndex = 2;
  19165. }
  19166. else
  19167. {
  19168. tempIndex = gun_index;
  19169. }
  19170. for (int index = 0; index < AC_QUANTITY; index++)
  19171. {
  19172. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19173. {
  19174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19175. }
  19176. }// End of for AC_QUANTITY
  19177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19178. }
  19179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19184. }
  19185. //2.9====================================== Voltage L2 ====================================================
  19186. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19187. {
  19188. // AC 3 phase L2 volatge
  19189. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19190. {
  19191. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19192. {
  19193. tempIndex = 2;
  19194. }
  19195. else
  19196. {
  19197. tempIndex = gun_index;
  19198. }
  19199. for (int index = 0; index < AC_QUANTITY; index++)
  19200. {
  19201. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19202. {
  19203. 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
  19204. }
  19205. } // END OF FOR AC_QUANTITY
  19206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19207. }
  19208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19213. }
  19214. //2.10====================================== Voltage L3 ====================================================
  19215. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19216. {
  19217. // AC 3 phase L3 volatge
  19218. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19219. {
  19220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19221. {
  19222. tempIndex = 2;
  19223. }
  19224. else
  19225. {
  19226. tempIndex = gun_index;
  19227. }
  19228. for (int index = 0; index < AC_QUANTITY; index++)
  19229. {
  19230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19231. {
  19232. 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
  19233. }
  19234. } // END OF FOR AC_QUANTITY
  19235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19236. }
  19237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19242. }
  19243. //====================== Start SoC ================================
  19244. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19245. {
  19246. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19247. 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))
  19248. {
  19249. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19250. {
  19251. tempIndex = ((gun_index==2) ? 1: 0);
  19252. }
  19253. else
  19254. {
  19255. tempIndex = gun_index;
  19256. }
  19257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19258. {
  19259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19260. {
  19261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19262. {
  19263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19264. }
  19265. }
  19266. }
  19267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19268. {
  19269. for (int index = 0; index < CCS_QUANTITY; index++)
  19270. {
  19271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19272. {
  19273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19274. }
  19275. }
  19276. }
  19277. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19278. {
  19279. for (int index = 0; index < GB_QUANTITY; index++)
  19280. {
  19281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19282. {
  19283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19284. }
  19285. }
  19286. }
  19287. else if(gunType[gun_index] == GUN_TYPE_DO)
  19288. {
  19289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19290. {
  19291. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19292. {
  19293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19294. }
  19295. }
  19296. }
  19297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19303. } // END FOR DC CASE
  19304. }
  19305. //======================================== Message create ==============================================
  19306. json_object *StopTransaction = json_object_new_object();
  19307. json_object *transactionDatas = json_object_new_array();
  19308. json_object *sampledValues = json_object_new_array();
  19309. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19310. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19311. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19312. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19313. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19314. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19315. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19316. {
  19317. json_object *transactionData = json_object_new_object();
  19318. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19319. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19320. {
  19321. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19322. {
  19323. json_object *sampledValue = json_object_new_object();
  19324. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19325. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19326. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19327. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19328. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19329. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19330. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19331. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19332. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19333. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19334. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19335. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19336. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19337. json_object_array_add(sampledValues, sampledValue);
  19338. }
  19339. }
  19340. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19341. json_object_array_add(transactionDatas, transactionData);
  19342. }
  19343. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19344. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19345. ,MESSAGE_TYPE_CALL
  19346. ,guid
  19347. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19348. json_object_put(StopTransaction);
  19349. // Check File "TempStopTransaction" Exist
  19350. if((access(TempStopTransaction,F_OK))!=-1)
  19351. {
  19352. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19353. fclose(fopen(TempStopTransaction, "w"));
  19354. }
  19355. else
  19356. {
  19357. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19358. FILE *log = fopen(TempStopTransaction, "w+");
  19359. if(log == NULL)
  19360. {
  19361. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19362. return ;
  19363. }
  19364. else
  19365. {
  19366. fclose(log);
  19367. }
  19368. }
  19369. //Add TempStopTransaction | Update TempStopTransaction
  19370. // open file for writing
  19371. FILE *outfile;
  19372. outfile = fopen (TempStopTransaction, "a");
  19373. //DEBUG_INFO("data = %s\n", queuedata);
  19374. fputs(queuedata, outfile);
  19375. fputs("\n", outfile);
  19376. fclose (outfile);
  19377. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19378. OCPP_updatePeriodEnergy(gun_index);
  19379. }
  19380. void checkTempStopTransaction(int gun_index)
  19381. {
  19382. FILE *fptr1;
  19383. char ch;
  19384. char str[QUEUE_MESSAGE_LENGTH]={0};
  19385. char guid[37]={0};
  19386. char tempdata[65]={0};
  19387. char connectorStr[2]={0};
  19388. char TempStopTransaction[256];
  19389. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19390. fptr1 = fopen(TempStopTransaction, "r");
  19391. //TempStopTransaction格式: 槍號,StopTransaction封包
  19392. if (!fptr1)
  19393. {
  19394. //printf(" File not found or unable to open the input file!!\n");
  19395. return ;
  19396. }
  19397. ch=fgetc(fptr1);
  19398. //printf(" Now the content of the file %s is : \n",fname);
  19399. rewind(fptr1);
  19400. if(ch!=EOF)
  19401. {
  19402. // copy all contents to the temporary file except the specific line
  19403. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19404. {
  19405. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19406. if(str[0]=='\0')
  19407. {
  19408. break;
  19409. }
  19410. //TempStopTransaction格式: 槍號,StopTransaction封包
  19411. strncpy(connectorStr, str, 1);
  19412. if(atoi(connectorStr) != (gun_index+1))
  19413. {
  19414. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19415. fclose(fptr1);
  19416. return ;
  19417. }
  19418. //random_uuid(guid);
  19419. strncpy(guid, str+6, 36); //copy guid
  19420. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19421. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19422. {
  19423. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19424. }
  19425. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19426. OCPP_insert_transaction_msg(NO, str);
  19427. memset(str,0,ARRAY_SIZE(str));
  19428. }
  19429. }
  19430. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19431. fclose(fptr1);
  19432. remove(TempStopTransaction); // remove the original file
  19433. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19434. }
  19435. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19436. {
  19437. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19438. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19439. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19440. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19441. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19442. }
  19443. int GetWebSocketPingInterval(void)
  19444. {
  19445. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19446. }
  19447. int GetServerSign(void)
  19448. {
  19449. return server_sign;
  19450. }
  19451. uint8_t GetOcppSecurityProfile()
  19452. {
  19453. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19454. }
  19455. void GetOcppChargerBoxId(uint8_t *data)
  19456. {
  19457. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19458. }
  19459. void GetOcppSecurityPassword(uint8_t *data)
  19460. {
  19461. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19462. }
  19463. void SetOcppVersion(uint8_t *version)
  19464. {
  19465. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19466. DEBUG_INFO("ocpp version: %s\n", version);
  19467. if(strstr((char*)version, "ocpp1.6") != NULL)
  19468. {
  19469. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19470. }
  19471. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19472. {
  19473. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19474. system("pkill OcppBackend");
  19475. }
  19476. }
  19477. void SetServerSign(int value)
  19478. {
  19479. server_sign = value;
  19480. }
  19481. int GetBootNotificationInterval(void)
  19482. {
  19483. return BootNotificationInterval;
  19484. }
  19485. int GetInternetConn(void)
  19486. {
  19487. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19488. }
  19489. int GetBackendConnectionTimeout(void)
  19490. {
  19491. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19492. }
  19493. int isConnectorInitMode(int gun_index)
  19494. {
  19495. int tempIndex = 0;
  19496. int result = TRUE;
  19497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19499. {
  19500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19501. {
  19502. tempIndex = ((gun_index==2) ? 1: 0);
  19503. }
  19504. else
  19505. {
  19506. tempIndex = gun_index;
  19507. }
  19508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19509. {
  19510. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19511. {
  19512. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19513. } //end of the same index
  19514. }//end of for CHAdeMO_QUANTITY
  19515. }
  19516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19517. {
  19518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19519. {
  19520. tempIndex = ((gun_index==2) ? 1: 0);
  19521. }
  19522. else
  19523. {
  19524. tempIndex = gun_index;
  19525. }
  19526. for (int index = 0; index < CCS_QUANTITY; index++)
  19527. {
  19528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19529. {
  19530. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19531. } //end of the same index
  19532. } // end of for CCS_QUANTITY
  19533. }
  19534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19535. {
  19536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19537. {
  19538. tempIndex = ((gun_index==2) ? 1: 0);
  19539. }
  19540. else
  19541. {
  19542. tempIndex = gun_index;
  19543. }
  19544. for (int index = 0; index < GB_QUANTITY; index++)
  19545. {
  19546. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19547. {
  19548. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19549. } //end of the same index
  19550. } // end of for GB_QUANTITY
  19551. }
  19552. else if(gunType[gun_index] == GUN_TYPE_DO)
  19553. {
  19554. tempIndex = gun_index;
  19555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19556. {
  19557. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19558. {
  19559. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19560. } //end of the same index
  19561. }
  19562. }
  19563. else
  19564. {
  19565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19566. {
  19567. tempIndex = 2;
  19568. }
  19569. else
  19570. {
  19571. tempIndex = gun_index;
  19572. }
  19573. for (int index = 0; index < AC_QUANTITY; index++)
  19574. {
  19575. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19576. {
  19577. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19578. }//end of the same index
  19579. }//end of for AC_QUANTITY
  19580. }
  19581. return result;
  19582. }
  19583. void refreshProcDogTimer()
  19584. {
  19585. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19586. }
  19587. void InitialSystemValue(void)
  19588. {
  19589. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19590. locallistVersion=0;
  19591. BootNotificationInterval = 0;
  19592. authorizeRetryTimes = 0;
  19593. GunStatusInterval = 10;
  19594. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19595. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19596. //Hear Beat
  19597. HeartBeatWithNOResponse = 0;
  19598. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19599. FirstHeartBeat = 0;
  19600. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19601. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19602. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19603. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19604. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19605. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19606. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19607. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19608. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19609. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19610. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19611. //Status && ConnectorPlugIn Setting
  19612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19613. {
  19614. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19615. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19616. }
  19617. for (int index = 0; index < CCS_QUANTITY; index++)
  19618. {
  19619. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19620. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19621. }
  19622. for (int index = 0; index < GB_QUANTITY; index++)
  19623. {
  19624. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19625. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19626. }
  19627. for (int index = 0; index < AC_QUANTITY; index++)
  19628. {
  19629. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19630. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19631. }
  19632. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19633. {
  19634. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19635. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19636. }
  19637. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19638. {
  19639. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19641. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19642. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19643. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19644. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19645. }
  19646. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19647. refreshStartTimer(&clientTime.Heartbeat);
  19648. sleep(1);
  19649. }
  19650. void LWS_Send(char *str)
  19651. {
  19652. //=====================================================
  19653. // Check InternetConn 0: disconnected, 1: connected
  19654. //====================================================
  19655. if(GetOcppConnStatus() == 0)
  19656. {
  19657. DEBUG_INFO("offline now !!!\n");
  19658. return;
  19659. }
  19660. // Only disable isWebsocketSendable operation initiated by charger
  19661. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19662. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19663. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19664. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19665. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19666. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19667. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19668. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19669. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19670. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19671. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19672. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19673. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19674. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19675. {
  19676. isWebsocketSendable = 0;
  19677. }
  19678. pthread_mutex_lock(&lock_send);
  19679. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19680. sprintf((char *)SendBuffer, "%s", str);
  19681. SendBufLen = strlen(str);
  19682. pthread_mutex_unlock(&lock_send);
  19683. lws_callback_on_writable(wsi_client);
  19684. //lws_service(context, 0);
  19685. //sleep(1);
  19686. }
  19687. void LWS_SendNow(char *str)
  19688. {
  19689. //=====================================================
  19690. // Check InternetConn 0: disconnected, 1: connected
  19691. //====================================================
  19692. if(GetOcppConnStatus() == 0)
  19693. {
  19694. DEBUG_INFO("offline now !!!\n");
  19695. return;
  19696. }
  19697. // Only disable isWebsocketSendable operation initiated by charger
  19698. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19699. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19700. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19701. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19702. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19703. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19704. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19705. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19706. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19707. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19708. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19709. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19710. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19711. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19712. {
  19713. isWebsocketSendable = 0;
  19714. }
  19715. pthread_mutex_lock(&lock_send);
  19716. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19717. sprintf((char *)SendBuffer, "%s", str);
  19718. SendBufLen = strlen(str);
  19719. pthread_mutex_unlock(&lock_send);
  19720. lws_callback_on_writable(wsi_client);
  19721. lws_service(context, 0);
  19722. //sleep(1);
  19723. }