MessageHandler.c 983 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518
  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. isQueueSendable = 1;
  14346. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14347. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14348. //-----------Start : write to the Queue TransactionId file -----------------//
  14349. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14350. {}
  14351. else
  14352. {
  14353. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14354. if(log == NULL)
  14355. {
  14356. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14357. return ;
  14358. }
  14359. else
  14360. {
  14361. fclose(log);
  14362. }
  14363. }
  14364. // open file for writing
  14365. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14366. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14367. {
  14368. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14369. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14370. fputs(data, outfile);
  14371. fclose (outfile);
  14372. }
  14373. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14374. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14375. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14376. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14377. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14378. }
  14379. void handleStatusNotificationResponse(char *payload, int gun_index)
  14380. {
  14381. mtrace();
  14382. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14383. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14384. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14385. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14386. }
  14387. void handleStopTransactionnResponse(char *payload, int gun_index)
  14388. {
  14389. mtrace();
  14390. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14391. json_object *StopTransaction;
  14392. StopTransaction = json_tokener_parse(payload);
  14393. if(!is_error(StopTransaction))
  14394. {
  14395. // Optional data
  14396. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14397. {
  14398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14399. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14401. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14403. }
  14404. }
  14405. json_object_put(StopTransaction);
  14406. isQueueSendable = 1;
  14407. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14408. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14409. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14410. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14411. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14412. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14413. }
  14414. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14415. {
  14416. mtrace();
  14417. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14418. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14419. }
  14420. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14421. {
  14422. mtrace();
  14423. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14424. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14425. }
  14426. void handleSignCertificateResponse(char *payload, int gun_index)
  14427. {
  14428. mtrace();
  14429. DEBUG_INFO("handleSignCertificateResponse...\n");
  14430. json_object *SignCertificate;
  14431. SignCertificate = json_tokener_parse(payload);
  14432. if(!is_error(SignCertificate))
  14433. {
  14434. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14435. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14436. }
  14437. json_object_put(SignCertificate);
  14438. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14439. }
  14440. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14441. {
  14442. mtrace();
  14443. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14444. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14445. }
  14446. //==========================================
  14447. // Handle Error routine
  14448. //==========================================
  14449. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14450. {
  14451. mtrace();
  14452. #ifdef SystemLogMessage
  14453. DEBUG_INFO("errorCode: %s\n", errorCode);
  14454. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14455. DEBUG_INFO("errorDetails: %s\n", payload);
  14456. #endif
  14457. }
  14458. //===============================================
  14459. // Common routine
  14460. //===============================================
  14461. int initialConfigurationTable(void)
  14462. {
  14463. //clock_t start_t, end_t, total_t;
  14464. FILE *fp;
  14465. FILE *outfile;
  14466. char str[512]={0};
  14467. char sstr[256]={0};
  14468. int c = 0;
  14469. char *loc;
  14470. int confVersion = 17;
  14471. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14472. //start_t = clock();
  14473. //printf("Starting of the program, start_t = %ld\n", start_t);
  14474. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14475. // Check configuration file size is correct
  14476. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14477. {
  14478. struct stat st;
  14479. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14480. if(st.st_size < 3100)
  14481. {
  14482. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14483. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14484. }
  14485. }
  14486. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14487. {
  14488. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14489. if(outfile == NULL)
  14490. {
  14491. DEBUG_INFO("Error opening file\n");
  14492. return FALSE;
  14493. }
  14494. /*Core Profile*/
  14495. //AllowOfflineTxForUnknownId
  14496. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14500. //AuthorizationCacheEnabled
  14501. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14505. //AuthorizeRemoteTxRequests
  14506. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14510. //BlinkRepeat
  14511. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14515. //ClockAlignedDataInterval
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14520. //ConnectionTimeOut
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14525. //GetConfigurationMaxKeys
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14530. // HeartbeatInterval
  14531. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14535. // LightIntensity
  14536. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14540. // LocalAuthorizeOffline
  14541. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14545. // LocalPreAuthorize
  14546. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14550. // MaxEnergyOnInvalidId
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14555. // MeterValuesAlignedData
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14559. 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" );
  14560. else
  14561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14563. // MeterValuesAlignedDataMaxLength
  14564. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14568. else
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14571. // MeterValuesSampledData
  14572. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14575. 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" );
  14576. else
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14579. // MeterValuesSampledDataMaxLength
  14580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14584. else
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14587. // MeterValueSampleInterval
  14588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14592. // MinimumStatusDuration
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14596. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14598. // NumberOfConnectors
  14599. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14602. {
  14603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14604. }
  14605. else
  14606. {
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14608. }
  14609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14610. // ResetRetries
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14615. // ConnectorPhaseRotation
  14616. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14620. // ConnectorPhaseRotationMaxLength
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14625. // StopTransactionOnEVSideDisconnect
  14626. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14630. // StopTransactionOnInvalidId
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14635. // StopTxnAlignedData
  14636. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14640. // StopTxnAlignedDataMaxLength
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14645. // StopTxnSampledData
  14646. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14650. else
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14653. // StopTxnSampledDataMaxLength
  14654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14657. {
  14658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14659. }
  14660. else
  14661. {
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14663. }
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14665. // SupportedFeatureProfiles
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14670. // SupportedFeatureProfilesMaxLength
  14671. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14675. // TransactionMessageAttempts
  14676. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14679. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14681. // TransactionMessageRetryInterval
  14682. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14685. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14687. // UnlockConnectorOnEVSideDisconnect
  14688. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14692. // WebSocketPingInterval
  14693. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14697. // QueueOffLineMeterValues
  14698. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14702. // AuthorizationKey
  14703. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14707. // SecurityProfile
  14708. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14712. // DefaultPrice
  14713. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14717. // CustomDisplayCostAndPrice
  14718. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14722. // CustomIdleFeeAfterStop
  14723. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14727. // TimeOffset
  14728. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14732. // NextTimeOffsetTransitionDateTime
  14733. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14737. // TimeOffsetNextTransition
  14738. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14742. // SystemUptimeSec
  14743. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14747. // FreeVend
  14748. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14752. // FreeVendIdtag
  14753. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14757. // OcppServer
  14758. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14760. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14762. // MaintainServer
  14763. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14765. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14767. // StatusNotificationPeriodically
  14768. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14772. // StatusNotificationInterval
  14773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14777. // PreAuthAmount
  14778. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14782. // isEnableLocalPowerSharing
  14783. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14787. // PowerSharingServerIP
  14788. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14790. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14792. // EVCCID_PREFIX
  14793. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14797. // OffLineMaxChargingPower
  14798. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14802. // Configuration Version
  14803. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14807. //* Local Auth List Management Profile*/
  14808. #if 0
  14809. //For OCTT Test Case
  14810. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14813. #endif
  14814. #if 1
  14815. //LocalAuthListEnabled
  14816. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14820. #endif
  14821. //LocalAuthListMaxLength
  14822. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14826. //SendLocalListMaxLength
  14827. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14831. //ReserveConnectorZeroSupported
  14832. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14836. //* Smart Charging Profile */
  14837. //ChargeProfileMaxStackLevel
  14838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14842. // ChargingScheduleAllowedChargingRateUnit
  14843. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14847. // ChargingScheduleMaxPeriods
  14848. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14852. // ConnectorSwitch3to1PhaseSupported
  14853. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14857. // MaxChargingProfilesInstalled
  14858. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14862. fclose(outfile);
  14863. }
  14864. else
  14865. {
  14866. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14867. char keystr[60]={0};
  14868. char readonlystr[10]={0};
  14869. char valuestr[256]={0};
  14870. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14871. if(fp == NULL) {
  14872. DEBUG_INFO("Error opening file");
  14873. return FALSE;
  14874. }
  14875. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14876. {
  14877. //DEBUG_INFO("Get Configuration \n");
  14878. if(strlen(str) > 0)
  14879. {
  14880. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14881. //*************************key*********************************/
  14882. if(strstr(str, "key") != NULL)
  14883. {
  14884. loc = strstr(str, "key");
  14885. c = 0;
  14886. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14887. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14888. {
  14889. sstr[c] = loc[strlen("key")+3+c];
  14890. c++;
  14891. }
  14892. sstr[c] = '\0';
  14893. strcpy(keystr,sstr);
  14894. }
  14895. //*************************readonly*********************************/
  14896. if(strstr(str, "readonly") != NULL)
  14897. {
  14898. loc = strstr(str, "readonly");
  14899. c = 0;
  14900. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14901. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14902. {
  14903. sstr[c] = loc[strlen("readonly")+2+c];
  14904. c++;
  14905. }
  14906. sstr[c] = '\0';
  14907. strcpy(readonlystr,sstr);
  14908. }
  14909. //*************************value*********************************/
  14910. if(strstr(str, "value") != NULL)
  14911. {
  14912. loc = strstr(str, "value");
  14913. c = 0;
  14914. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14915. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14916. {
  14917. sstr[c] = loc[strlen("value")+3+c];
  14918. c++;
  14919. }
  14920. sstr[c] = '\0';
  14921. strcpy(valuestr,sstr);
  14922. }
  14923. // DEBUG_INFO("keystr=%s\n",keystr);
  14924. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14925. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14926. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14927. {
  14928. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14929. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14931. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14932. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14933. }
  14934. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14935. {
  14936. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14937. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14939. }
  14940. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14941. {
  14942. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14944. }
  14945. if(strcmp(keystr, "BlinkRepeat") == 0)
  14946. {
  14947. //Charger.BlinkRepeat = Integer.parseInt(value);
  14948. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14950. }
  14951. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14952. {
  14953. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14955. }
  14956. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14957. {
  14958. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14960. }
  14961. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14962. {
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14965. }
  14966. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14967. {
  14968. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14970. HeartBeatWaitTime = atoi(valuestr);
  14971. }
  14972. if(strcmp(keystr, "LightIntensity") == 0)
  14973. {
  14974. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14976. }
  14977. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14978. {
  14979. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14981. }
  14982. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14983. {
  14984. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14986. }
  14987. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14988. {
  14989. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14991. }
  14992. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14993. {
  14994. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14996. }
  14997. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14998. {
  14999. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15001. }
  15002. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15003. {
  15004. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15006. }
  15007. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15008. {
  15009. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15011. }
  15012. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15013. {
  15014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15016. }
  15017. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15018. {
  15019. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15021. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15022. }
  15023. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15024. {
  15025. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15027. }
  15028. if(strcmp(keystr, "ResetRetries") == 0)
  15029. {
  15030. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15032. }
  15033. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15034. {
  15035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15037. }
  15038. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15039. {
  15040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15042. }
  15043. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15044. {
  15045. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15047. }
  15048. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15049. {
  15050. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15052. }
  15053. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15054. {
  15055. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15057. }
  15058. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15059. {
  15060. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15062. }
  15063. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15064. {
  15065. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15067. }
  15068. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15069. {
  15070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15072. }
  15073. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15074. {
  15075. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15077. }
  15078. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15079. {
  15080. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15082. }
  15083. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15084. {
  15085. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15087. TransactionMessageAttemptsValue = atoi(valuestr);
  15088. }
  15089. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15090. {
  15091. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15093. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15094. }
  15095. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15096. {
  15097. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15099. }
  15100. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15101. {
  15102. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15104. }
  15105. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15106. {
  15107. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15109. }
  15110. if(strcmp(keystr, "AuthorizationKey") == 0)
  15111. {
  15112. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15113. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15115. }
  15116. if(strcmp(keystr, "SecurityProfile") == 0)
  15117. {
  15118. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15120. }
  15121. if(strcmp(keystr, "DefaultPrice") == 0)
  15122. {
  15123. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15125. }
  15126. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15127. {
  15128. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15130. }
  15131. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15132. {
  15133. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15135. }
  15136. if(strcmp(keystr, "TimeOffset") == 0)
  15137. {
  15138. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15140. }
  15141. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15142. {
  15143. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15145. }
  15146. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15147. {
  15148. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15150. }
  15151. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15152. {
  15153. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15155. }
  15156. if(strcmp(keystr, "FreeVend") == 0)
  15157. {
  15158. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15160. }
  15161. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15162. {
  15163. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15165. }
  15166. if(strcmp(keystr, "OcppServer") == 0)
  15167. {
  15168. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15169. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15170. }
  15171. if(strcmp(keystr, "MaintainServer") == 0)
  15172. {
  15173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15174. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15175. }
  15176. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15177. {
  15178. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15180. }
  15181. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15182. {
  15183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15185. }
  15186. if(strcmp(keystr, "PreAuthAmount") == 0)
  15187. {
  15188. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15190. }
  15191. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15192. {
  15193. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15195. }
  15196. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15197. {
  15198. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15199. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15200. }
  15201. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15202. {
  15203. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15205. }
  15206. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15207. {
  15208. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15210. }
  15211. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15212. {
  15213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15215. }
  15216. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15217. {
  15218. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15220. }
  15221. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15222. {
  15223. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15225. }
  15226. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15227. {
  15228. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15230. }
  15231. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15232. {
  15233. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15235. }
  15236. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15237. {
  15238. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15240. }
  15241. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15242. {
  15243. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15245. }
  15246. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15247. {
  15248. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15250. }
  15251. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15252. {
  15253. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15255. }
  15256. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15257. {
  15258. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15260. }
  15261. }
  15262. }
  15263. fclose(fp);
  15264. }
  15265. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15266. {
  15267. return PASS;
  15268. }
  15269. else
  15270. {
  15271. return FAIL;
  15272. }
  15273. }
  15274. void StoreConfigurationTable(void)
  15275. {
  15276. FILE *outfile;
  15277. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15278. if(outfile == NULL)
  15279. {
  15280. DEBUG_INFO("Error opening file");
  15281. return ;
  15282. }
  15283. /*Core Profile*/
  15284. //AllowOfflineTxForUnknownId
  15285. /*
  15286. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15287. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15290. */
  15291. //DEBUG_INFO("data=%s\n",data);
  15292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15293. //AuthorizationCacheEnabled
  15294. /*
  15295. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15298. */
  15299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15300. //AuthorizeRemoteTxRequests
  15301. /*
  15302. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15305. */
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15307. //BlinkRepeat
  15308. /*
  15309. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15312. */
  15313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15314. //ClockAlignedDataInterval
  15315. /*
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15319. */
  15320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15321. //ConnectionTimeOut
  15322. /*
  15323. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15326. */
  15327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15328. //GetConfigurationMaxKeys
  15329. /*
  15330. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15333. */
  15334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15335. // HeartbeatInterval
  15336. /*
  15337. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15340. */
  15341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15342. // LightIntensity
  15343. /*
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15347. */
  15348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15349. // LocalAuthorizeOffline
  15350. /*
  15351. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15354. */
  15355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15356. // LocalPreAuthorize
  15357. /*
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15361. */
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15363. // MaxEnergyOnInvalidId
  15364. /*
  15365. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15368. */
  15369. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15371. // MeterValuesAlignedData
  15372. /*
  15373. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15376. */
  15377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15378. // MeterValuesAlignedDataMaxLength
  15379. /*
  15380. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15383. */
  15384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15385. // MeterValuesSampledData
  15386. /*
  15387. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15390. */
  15391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15392. // MeterValuesSampledDataMaxLength
  15393. /*
  15394. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15397. */
  15398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15399. // MeterValueSampleInterval
  15400. /*
  15401. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15404. */
  15405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15406. // MinimumStatusDuration
  15407. /*
  15408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15411. */
  15412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15413. // NumberOfConnectors
  15414. /*
  15415. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15417. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15418. {
  15419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15420. }
  15421. else
  15422. {
  15423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15424. }
  15425. */
  15426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15427. // ResetRetries
  15428. /*
  15429. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15432. */
  15433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15434. // ConnectorPhaseRotation
  15435. /*
  15436. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15439. */
  15440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15441. // ConnectorPhaseRotationMaxLength
  15442. /*
  15443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15446. */
  15447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15448. // StopTransactionOnEVSideDisconnect
  15449. /*
  15450. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15453. */
  15454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15455. // StopTransactionOnInvalidId
  15456. /*
  15457. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15460. */
  15461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15462. // StopTxnAlignedData
  15463. /*
  15464. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15467. */
  15468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15469. // StopTxnAlignedDataMaxLength
  15470. /*
  15471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15474. */
  15475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15476. // StopTxnSampledData
  15477. /*
  15478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15481. */
  15482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15483. // StopTxnSampledDataMaxLength
  15484. /*
  15485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15488. */
  15489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15490. // SupportedFeatureProfiles
  15491. /*
  15492. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15495. */
  15496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15497. // SupportedFeatureProfilesMaxLength
  15498. /*
  15499. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15502. */
  15503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15504. // TransactionMessageAttempts
  15505. /*
  15506. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15509. */
  15510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15511. // TransactionMessageRetryInterval
  15512. /*
  15513. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15516. */
  15517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15518. // UnlockConnectorOnEVSideDisconnect
  15519. /*
  15520. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15523. */
  15524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15525. // WebSocketPingInterval
  15526. /*
  15527. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15530. */
  15531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15532. // QueueOffLineMeterValues
  15533. /*
  15534. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15537. */
  15538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15539. // AuthorizationKey
  15540. /*
  15541. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15544. */
  15545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15546. // SecurityProfile
  15547. /*
  15548. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15551. */
  15552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15553. // DefaultPrice
  15554. /*
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15558. */
  15559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15560. // CustomDisplayCostAndPrice
  15561. /*
  15562. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15565. */
  15566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15567. // CustomIdleFeeAfterStop
  15568. /*
  15569. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15572. */
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15574. // TimeOffset
  15575. /*
  15576. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15579. */
  15580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15581. // NextTimeOffsetTransitionDateTime
  15582. /*
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15586. */
  15587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15588. // TimeOffsetNextTransition
  15589. /*
  15590. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15593. */
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15595. // SystemUptimeSec
  15596. /*
  15597. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15600. */
  15601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15602. // FreeVend
  15603. /*
  15604. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15607. */
  15608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15609. // FreeVendIdtag
  15610. /*
  15611. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15614. */
  15615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15616. // OcppServer
  15617. /*
  15618. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15621. */
  15622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15623. // MaintainServer
  15624. /*
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15628. */
  15629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15630. // StatusNotificationPeriodically
  15631. /*
  15632. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15635. */
  15636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15637. // StatusNotificationInterval
  15638. /*
  15639. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15642. */
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15644. // PreAuthAmount
  15645. /*
  15646. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15649. */
  15650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15651. // isEnableLocalPowerSharing
  15652. /*
  15653. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15656. */
  15657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15658. // PowerSharingServerIP
  15659. /*
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15663. */
  15664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15665. // EVCCID_PREFIX
  15666. /*
  15667. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15670. */
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15672. // OffLineMaxChargingPower
  15673. /*
  15674. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15677. */
  15678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15679. // ConfigurationVersion
  15680. /*
  15681. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15684. */
  15685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15686. //* Local Auth List Management Profile*/
  15687. //LocalAuthListEnabled
  15688. /*
  15689. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15692. */
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15694. //LocalAuthListMaxLength
  15695. /*
  15696. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15699. */
  15700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15701. //SendLocalListMaxLength
  15702. /*
  15703. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15706. */
  15707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15708. //ReserveConnectorZeroSupported
  15709. /*
  15710. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15713. */
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15715. //* Smart Charging Profile */
  15716. //ChargeProfileMaxStackLevel
  15717. /*
  15718. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15721. */
  15722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15723. // ChargingScheduleAllowedChargingRateUnit
  15724. /*
  15725. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15728. */
  15729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15730. // ChargingScheduleMaxPeriods
  15731. /*
  15732. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15735. */
  15736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15737. // ConnectorSwitch3to1PhaseSupported
  15738. /*
  15739. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15742. */
  15743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15744. // MaxChargingProfilesInstalled
  15745. /*
  15746. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15749. */
  15750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15751. fclose(outfile);
  15752. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15753. }
  15754. void getKeyValue(char *keyReq)
  15755. {
  15756. int isEmpty = FALSE;
  15757. int isKnowKey = FALSE;
  15758. DEBUG_INFO("keyReq = %s\n", keyReq);
  15759. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15760. isEmpty = TRUE;
  15761. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15766. {
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15768. }
  15769. else
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15772. }
  15773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15774. isKnowKey = TRUE;
  15775. }
  15776. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15783. }
  15784. else
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15787. }
  15788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15789. isKnowKey = TRUE;
  15790. }
  15791. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15798. }
  15799. else
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15802. }
  15803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15804. isKnowKey = TRUE;
  15805. }
  15806. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15807. {
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15811. {
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15813. }
  15814. else
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15817. }
  15818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15819. isKnowKey = TRUE;
  15820. }
  15821. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15822. {
  15823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15826. {
  15827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15828. }
  15829. else
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15832. }
  15833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15834. isKnowKey = TRUE;
  15835. }
  15836. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15837. {
  15838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15841. {
  15842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15843. }
  15844. else
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15847. }
  15848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15849. isKnowKey = TRUE;
  15850. }
  15851. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15852. {
  15853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15856. {
  15857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15858. }
  15859. else
  15860. {
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15862. }
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15864. isKnowKey = TRUE;
  15865. }
  15866. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15867. {
  15868. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15871. {
  15872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15873. }
  15874. else
  15875. {
  15876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15877. }
  15878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15879. isKnowKey = TRUE;
  15880. }
  15881. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15882. {
  15883. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15886. {
  15887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15888. }
  15889. else
  15890. {
  15891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15892. }
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15894. isKnowKey = TRUE;
  15895. }
  15896. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15897. {
  15898. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15901. {
  15902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15903. }
  15904. else
  15905. {
  15906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15907. }
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15909. isKnowKey = TRUE;
  15910. }
  15911. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15912. {
  15913. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15916. {
  15917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15918. }
  15919. else
  15920. {
  15921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15922. }
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15924. isKnowKey = TRUE;
  15925. }
  15926. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15927. {
  15928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15931. {
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15933. }
  15934. else
  15935. {
  15936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15937. }
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15939. isKnowKey = TRUE;
  15940. }
  15941. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15942. {
  15943. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15946. {
  15947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15948. }
  15949. else
  15950. {
  15951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15952. }
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15954. isKnowKey = TRUE;
  15955. }
  15956. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15957. {
  15958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15961. {
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15963. }
  15964. else
  15965. {
  15966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15967. }
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15969. isKnowKey = TRUE;
  15970. }
  15971. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15972. {
  15973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15976. {
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15978. }
  15979. else
  15980. {
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15982. }
  15983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15984. isKnowKey = TRUE;
  15985. }
  15986. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15987. {
  15988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15991. {
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15993. }
  15994. else
  15995. {
  15996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15997. }
  15998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15999. isKnowKey = TRUE;
  16000. }
  16001. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16002. {
  16003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16008. }
  16009. else
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16012. }
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16014. isKnowKey = TRUE;
  16015. }
  16016. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16017. {
  16018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16021. {
  16022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16023. }
  16024. else
  16025. {
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16027. }
  16028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16029. isKnowKey = TRUE;
  16030. }
  16031. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16032. {
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16036. {
  16037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16038. }
  16039. else
  16040. {
  16041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16042. }
  16043. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16045. isKnowKey = TRUE;
  16046. }
  16047. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16048. {
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16054. }
  16055. else
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16058. }
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16060. isKnowKey = TRUE;
  16061. }
  16062. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16063. {
  16064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16069. }
  16070. else
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16073. }
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16075. isKnowKey = TRUE;
  16076. }
  16077. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16078. {
  16079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16084. }
  16085. else
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16088. }
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16090. isKnowKey = TRUE;
  16091. }
  16092. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16093. {
  16094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16099. }
  16100. else
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16103. }
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16105. isKnowKey = TRUE;
  16106. }
  16107. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16108. {
  16109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16114. }
  16115. else
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16118. }
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16120. isKnowKey = TRUE;
  16121. }
  16122. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16123. {
  16124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16129. }
  16130. else
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16133. }
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16135. isKnowKey = TRUE;
  16136. }
  16137. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16138. {
  16139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16142. {
  16143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16144. }
  16145. else
  16146. {
  16147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16148. }
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16150. isKnowKey = TRUE;
  16151. }
  16152. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16153. {
  16154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16157. {
  16158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16159. }
  16160. else
  16161. {
  16162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16163. }
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16165. isKnowKey = TRUE;
  16166. }
  16167. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16168. {
  16169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16172. {
  16173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16174. }
  16175. else
  16176. {
  16177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16178. }
  16179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16180. isKnowKey = TRUE;
  16181. }
  16182. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16183. {
  16184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16187. {
  16188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16189. }
  16190. else
  16191. {
  16192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16193. }
  16194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16195. isKnowKey = TRUE;
  16196. }
  16197. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16198. {
  16199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16202. {
  16203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16204. }
  16205. else
  16206. {
  16207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16208. }
  16209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16210. isKnowKey = TRUE;
  16211. }
  16212. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16213. {
  16214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16217. {
  16218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16219. }
  16220. else
  16221. {
  16222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16223. }
  16224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16225. isKnowKey = TRUE;
  16226. }
  16227. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16228. {
  16229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16232. {
  16233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16234. }
  16235. else
  16236. {
  16237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  16238. }
  16239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16240. isKnowKey = TRUE;
  16241. }
  16242. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16243. {
  16244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16247. {
  16248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16249. }
  16250. else
  16251. {
  16252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16253. }
  16254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16255. isKnowKey = TRUE;
  16256. }
  16257. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16258. {
  16259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16262. {
  16263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16264. }
  16265. else
  16266. {
  16267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16268. }
  16269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16270. isKnowKey = TRUE;
  16271. }
  16272. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16273. {
  16274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16277. {
  16278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16279. }
  16280. else
  16281. {
  16282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16283. }
  16284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16285. isKnowKey = TRUE;
  16286. }
  16287. /*
  16288. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16289. {
  16290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16293. {
  16294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16295. }
  16296. else
  16297. {
  16298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16299. }
  16300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16301. isKnowKey = TRUE;
  16302. }*/
  16303. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16304. {
  16305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16308. {
  16309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16310. }
  16311. else
  16312. {
  16313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16314. }
  16315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16316. isKnowKey = TRUE;
  16317. }
  16318. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16319. {
  16320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16323. {
  16324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16325. }
  16326. else
  16327. {
  16328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16329. }
  16330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16331. isKnowKey = TRUE;
  16332. }
  16333. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16334. {
  16335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16338. {
  16339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16340. }
  16341. else
  16342. {
  16343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16344. }
  16345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16346. isKnowKey = TRUE;
  16347. }
  16348. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16349. {
  16350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16353. {
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16355. }
  16356. else
  16357. {
  16358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16359. }
  16360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16361. isKnowKey = TRUE;
  16362. }
  16363. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16364. {
  16365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16368. {
  16369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16370. }
  16371. else
  16372. {
  16373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16374. }
  16375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16376. isKnowKey = TRUE;
  16377. }
  16378. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16379. {
  16380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16383. {
  16384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16385. }
  16386. else
  16387. {
  16388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16389. }
  16390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16391. isKnowKey = TRUE;
  16392. }
  16393. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16394. {
  16395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16398. {
  16399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16400. }
  16401. else
  16402. {
  16403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16404. }
  16405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16406. isKnowKey = TRUE;
  16407. }
  16408. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16409. {
  16410. struct sysinfo s_info;
  16411. int error = sysinfo(&s_info);
  16412. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16415. {
  16416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16417. }
  16418. else
  16419. {
  16420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16421. }
  16422. if(error != 0)
  16423. {
  16424. DEBUG_WARN("System uptime get error: %d\n", error);
  16425. }
  16426. else
  16427. {
  16428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16429. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16430. }
  16431. isKnowKey = TRUE;
  16432. }
  16433. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16434. {
  16435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16438. {
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16440. }
  16441. else
  16442. {
  16443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16444. }
  16445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16446. isKnowKey = TRUE;
  16447. }
  16448. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16449. {
  16450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16453. {
  16454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16455. }
  16456. else
  16457. {
  16458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16459. }
  16460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16461. isKnowKey = TRUE;
  16462. }
  16463. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16464. {
  16465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16468. {
  16469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16470. }
  16471. else
  16472. {
  16473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16474. }
  16475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16476. isKnowKey = TRUE;
  16477. }
  16478. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16479. {
  16480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16483. {
  16484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16485. }
  16486. else
  16487. {
  16488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16489. }
  16490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16491. isKnowKey = TRUE;
  16492. }
  16493. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16494. {
  16495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16498. {
  16499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16500. }
  16501. else
  16502. {
  16503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16504. }
  16505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16506. isKnowKey = TRUE;
  16507. }
  16508. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16509. {
  16510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16513. {
  16514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16515. }
  16516. else
  16517. {
  16518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16519. }
  16520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16521. isKnowKey = TRUE;
  16522. }
  16523. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16524. {
  16525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16528. {
  16529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16530. }
  16531. else
  16532. {
  16533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16534. }
  16535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16536. isKnowKey = TRUE;
  16537. }
  16538. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16539. {
  16540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16543. {
  16544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16545. }
  16546. else
  16547. {
  16548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16549. }
  16550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16551. isKnowKey = TRUE;
  16552. }
  16553. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16554. {
  16555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16558. {
  16559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16560. }
  16561. else
  16562. {
  16563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16564. }
  16565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16566. isKnowKey = TRUE;
  16567. }
  16568. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16569. {
  16570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16573. {
  16574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16575. }
  16576. else
  16577. {
  16578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16579. }
  16580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16581. isKnowKey = TRUE;
  16582. }
  16583. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16584. {
  16585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16588. {
  16589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16590. }
  16591. else
  16592. {
  16593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16594. }
  16595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16596. isKnowKey = TRUE;
  16597. }
  16598. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16599. {
  16600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16603. {
  16604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16605. }
  16606. else
  16607. {
  16608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16609. }
  16610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16611. isKnowKey = TRUE;
  16612. }
  16613. #if 1
  16614. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16615. {
  16616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16618. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16619. {
  16620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16621. }
  16622. else
  16623. {
  16624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16625. }
  16626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16627. isKnowKey = TRUE;
  16628. }
  16629. #endif
  16630. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16631. {
  16632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16634. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16635. {
  16636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16637. }
  16638. else
  16639. {
  16640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16641. }
  16642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16643. isKnowKey = TRUE;
  16644. }
  16645. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16646. {
  16647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16649. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16650. {
  16651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16652. }
  16653. else
  16654. {
  16655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16656. }
  16657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16658. isKnowKey = TRUE;
  16659. }
  16660. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16661. {
  16662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16664. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16665. {
  16666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16667. }
  16668. else
  16669. {
  16670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16671. }
  16672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16673. isKnowKey = TRUE;
  16674. }
  16675. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16676. {
  16677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16679. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16680. {
  16681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16682. }
  16683. else
  16684. {
  16685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16686. }
  16687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16688. isKnowKey = TRUE;
  16689. }
  16690. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16691. {
  16692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16694. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16695. {
  16696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16697. }
  16698. else
  16699. {
  16700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16701. }
  16702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16703. isKnowKey = TRUE;
  16704. }
  16705. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16706. {
  16707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16709. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16710. {
  16711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16712. }
  16713. else
  16714. {
  16715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16716. }
  16717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16718. isKnowKey = TRUE;
  16719. }
  16720. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16721. {
  16722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16724. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16725. {
  16726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16727. }
  16728. else
  16729. {
  16730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16731. }
  16732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16733. isKnowKey = TRUE;
  16734. }
  16735. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16736. {
  16737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16739. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16740. {
  16741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16742. }
  16743. else
  16744. {
  16745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16746. }
  16747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16748. isKnowKey = TRUE;
  16749. }
  16750. //=========================================================
  16751. if(!isEmpty && !isKnowKey)
  16752. {
  16753. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16754. strcpy(unknownkey[UnknownKeynum], keyReq);
  16755. UnknownKeynum = UnknownKeynum + 1;
  16756. }
  16757. }
  16758. void processUnkownKey(void)
  16759. {
  16760. DEBUG_INFO("processUnkownKey...\n");
  16761. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16762. for(int index=0; index < UnknownKeynum; index++)
  16763. {
  16764. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16765. {
  16766. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16767. }
  16768. }
  16769. }
  16770. int setKeyValue(char *key, char *value)
  16771. {
  16772. int isSuccess = NotSupported;
  16773. int check_ascii=0;
  16774. char str[501]={0};
  16775. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16776. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16777. {
  16778. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16780. {
  16781. strcpy(str, (const char*)value);
  16782. for(int i = 0; str[i]; i++){
  16783. str[i] = tolower(str[i]);
  16784. }
  16785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16786. isSuccess = ConfigurationStatus_Accepted;
  16787. }
  16788. else
  16789. {
  16790. isSuccess = ConfigurationStatus_Rejected;
  16791. }
  16792. }
  16793. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16794. {
  16795. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16797. {
  16798. strcpy(str, (const char*)value);
  16799. for(int i = 0; str[i]; i++){
  16800. str[i] = tolower(str[i]);
  16801. }
  16802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16803. isSuccess = ConfigurationStatus_Accepted;
  16804. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16805. }
  16806. else
  16807. {
  16808. isSuccess = ConfigurationStatus_Rejected;
  16809. }
  16810. }
  16811. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16812. {
  16813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16814. {
  16815. strcpy(str, (const char*)value);
  16816. for(int i = 0; str[i]; i++)
  16817. {
  16818. str[i] = tolower(str[i]);
  16819. }
  16820. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16822. isSuccess = ConfigurationStatus_Accepted;
  16823. }
  16824. else
  16825. {
  16826. isSuccess = ConfigurationStatus_Rejected;
  16827. }
  16828. }
  16829. if(strcmp(key, "BlinkRepeat") == 0)
  16830. {
  16831. //Charger.BlinkRepeat = Integer.parseInt(value);
  16832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16833. {
  16834. check_ascii = value[0];
  16835. if( (check_ascii < 48) || (check_ascii > 57) )
  16836. {
  16837. isSuccess = ConfigurationStatus_Rejected;
  16838. }
  16839. else
  16840. {
  16841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16842. isSuccess = ConfigurationStatus_Accepted;
  16843. }
  16844. }
  16845. else
  16846. {
  16847. isSuccess = ConfigurationStatus_Rejected;
  16848. }
  16849. }
  16850. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16851. {
  16852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16853. {
  16854. check_ascii = value[0];
  16855. if( (check_ascii < 48) || (check_ascii > 57) )
  16856. {
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. else
  16860. {
  16861. if((atoi(value) == 0) || (atoi(value) >= 5))
  16862. {
  16863. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16865. isSuccess = ConfigurationStatus_Accepted;
  16866. }
  16867. else
  16868. isSuccess = ConfigurationStatus_Rejected;
  16869. }
  16870. }
  16871. else
  16872. {
  16873. isSuccess = ConfigurationStatus_Rejected;
  16874. }
  16875. }
  16876. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16877. {
  16878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16879. {
  16880. check_ascii = value[0];
  16881. if( (check_ascii < 48) || (check_ascii > 57) )
  16882. {
  16883. isSuccess = ConfigurationStatus_Rejected;
  16884. }
  16885. else
  16886. {
  16887. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16889. isSuccess = ConfigurationStatus_Accepted;
  16890. }
  16891. }
  16892. else
  16893. {
  16894. isSuccess = ConfigurationStatus_Rejected;
  16895. }
  16896. }
  16897. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16898. {
  16899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16900. {
  16901. check_ascii = value[0];
  16902. if( (check_ascii < 48) || (check_ascii > 57) )
  16903. {
  16904. isSuccess = ConfigurationStatus_Rejected;
  16905. }
  16906. else
  16907. {
  16908. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16910. isSuccess = ConfigurationStatus_Accepted;
  16911. }
  16912. }
  16913. else
  16914. {
  16915. isSuccess = ConfigurationStatus_Rejected;
  16916. }
  16917. }
  16918. if(strcmp(key, "HeartbeatInterval") == 0)
  16919. {
  16920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16921. {
  16922. check_ascii = value[0];
  16923. if( (check_ascii < 48) || (check_ascii > 57) )
  16924. {
  16925. isSuccess = ConfigurationStatus_Rejected;
  16926. }
  16927. else
  16928. {
  16929. if((atoi(value) == 0) || (atoi(value) >= 10))
  16930. {
  16931. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16933. HeartBeatWaitTime = atoi(value);
  16934. isSuccess = ConfigurationStatus_Accepted;
  16935. }
  16936. else
  16937. {
  16938. isSuccess = ConfigurationStatus_Rejected;
  16939. }
  16940. }
  16941. }
  16942. else
  16943. {
  16944. isSuccess = ConfigurationStatus_Rejected;
  16945. }
  16946. }
  16947. if(strcmp(key, "LightIntensity") == 0)
  16948. {
  16949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16950. {
  16951. check_ascii = value[0];
  16952. if( (check_ascii < 48) || (check_ascii > 57) )
  16953. {
  16954. isSuccess = ConfigurationStatus_Rejected;
  16955. }
  16956. else
  16957. {
  16958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16959. isSuccess = ConfigurationStatus_Accepted;
  16960. }
  16961. }
  16962. else
  16963. {
  16964. isSuccess = ConfigurationStatus_Rejected;
  16965. }
  16966. }
  16967. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16968. {
  16969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16970. {
  16971. strcpy(str, (const char*)value);
  16972. for(int i = 0; str[i]; i++)
  16973. {
  16974. str[i] = tolower(str[i]);
  16975. }
  16976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16977. isSuccess = ConfigurationStatus_Accepted;
  16978. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16979. }
  16980. else
  16981. {
  16982. isSuccess = ConfigurationStatus_Rejected;
  16983. }
  16984. }
  16985. if(strcmp(key, "LocalPreAuthorize") == 0)
  16986. {
  16987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16988. {
  16989. strcpy(str, (const char*)value);
  16990. for(int i = 0; str[i]; i++)
  16991. {
  16992. str[i] = tolower(str[i]);
  16993. }
  16994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16995. isSuccess = ConfigurationStatus_Accepted;
  16996. }
  16997. else
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. }
  17002. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17003. {
  17004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17005. {
  17006. check_ascii = value[0];
  17007. if( (check_ascii < 48) || (check_ascii > 57) )
  17008. {
  17009. isSuccess = ConfigurationStatus_Rejected;
  17010. }
  17011. else
  17012. {
  17013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17014. isSuccess = ConfigurationStatus_Accepted;
  17015. }
  17016. }
  17017. else
  17018. {
  17019. isSuccess = ConfigurationStatus_Rejected;
  17020. }
  17021. }
  17022. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17023. {
  17024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17025. {
  17026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17027. isSuccess = ConfigurationStatus_Accepted;
  17028. }
  17029. else
  17030. {
  17031. isSuccess = ConfigurationStatus_Rejected;
  17032. }
  17033. }
  17034. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17035. {
  17036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17037. {
  17038. check_ascii = value[0];
  17039. if( (check_ascii < 48) || (check_ascii > 57) )
  17040. {
  17041. isSuccess = ConfigurationStatus_Rejected;
  17042. }
  17043. else
  17044. {
  17045. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17047. isSuccess = ConfigurationStatus_Accepted;
  17048. }
  17049. }
  17050. else
  17051. {
  17052. isSuccess = ConfigurationStatus_Rejected;
  17053. }
  17054. }
  17055. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17056. {
  17057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17058. {
  17059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17060. isSuccess = ConfigurationStatus_Accepted;
  17061. }
  17062. else
  17063. {
  17064. isSuccess = ConfigurationStatus_Rejected;
  17065. }
  17066. }
  17067. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17068. {
  17069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17070. {
  17071. check_ascii = value[0];
  17072. if( (check_ascii < 48) || (check_ascii > 57) )
  17073. {
  17074. isSuccess = ConfigurationStatus_Rejected;
  17075. }
  17076. else
  17077. {
  17078. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17080. isSuccess = ConfigurationStatus_Accepted;
  17081. }
  17082. }
  17083. else
  17084. {
  17085. isSuccess = ConfigurationStatus_Rejected;
  17086. }
  17087. }
  17088. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17089. {
  17090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17091. {
  17092. check_ascii = value[0];
  17093. if( (check_ascii < 48) || (check_ascii > 57) )
  17094. {
  17095. isSuccess = ConfigurationStatus_Rejected;
  17096. }
  17097. else
  17098. {
  17099. if((atoi(value) == 0) || (atoi(value) >= 3))
  17100. {
  17101. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17103. isSuccess = ConfigurationStatus_Accepted;
  17104. }
  17105. else
  17106. {
  17107. isSuccess = ConfigurationStatus_Rejected;
  17108. }
  17109. }
  17110. }
  17111. else
  17112. {
  17113. isSuccess = ConfigurationStatus_Rejected;
  17114. }
  17115. }
  17116. if(strcmp(key, "MinimumStatusDuration") == 0)
  17117. {
  17118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17119. {
  17120. check_ascii = value[0];
  17121. if( (check_ascii < 48) || (check_ascii > 57) )
  17122. {
  17123. isSuccess = ConfigurationStatus_Rejected;
  17124. }
  17125. else
  17126. {
  17127. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17128. {
  17129. isSuccess = ConfigurationStatus_Rejected;
  17130. }
  17131. else
  17132. {
  17133. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17135. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17136. isSuccess = ConfigurationStatus_Accepted;
  17137. }
  17138. }
  17139. }
  17140. else
  17141. {
  17142. isSuccess = ConfigurationStatus_Rejected;
  17143. }
  17144. }
  17145. if(strcmp(key, "NumberOfConnectors") == 0)
  17146. {
  17147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17148. {
  17149. check_ascii = value[0];
  17150. if( (check_ascii < 48) || (check_ascii > 57) )
  17151. {
  17152. isSuccess = ConfigurationStatus_Rejected;
  17153. }
  17154. else
  17155. {
  17156. //Charger.ResetRetries = Integer.parseInt(value);
  17157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17158. isSuccess = ConfigurationStatus_Accepted;
  17159. }
  17160. }
  17161. else
  17162. {
  17163. isSuccess = ConfigurationStatus_Rejected;
  17164. }
  17165. }
  17166. if(strcmp(key, "ResetRetries") == 0)
  17167. {
  17168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17169. {
  17170. check_ascii = value[0];
  17171. if( (check_ascii < 48) || (check_ascii > 57) )
  17172. {
  17173. isSuccess = ConfigurationStatus_Rejected;
  17174. }
  17175. else
  17176. {
  17177. //Charger.ResetRetries = Integer.parseInt(value);
  17178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17179. isSuccess = ConfigurationStatus_Accepted;
  17180. }
  17181. }
  17182. else
  17183. {
  17184. isSuccess = ConfigurationStatus_Rejected;
  17185. }
  17186. }
  17187. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17188. {
  17189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17190. {
  17191. strcpy(str, (const char*)value);
  17192. for(int i = 0; str[i]; i++)
  17193. {
  17194. str[i] = tolower(str[i]);
  17195. }
  17196. if(strcmp(str, "notapplicable")== 0)
  17197. {
  17198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17199. isSuccess = ConfigurationStatus_Accepted;
  17200. }
  17201. else if(strcmp(str, "unknown")== 0)
  17202. {
  17203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17204. isSuccess = ConfigurationStatus_Accepted;
  17205. }
  17206. else if(strcmp(str, "rst")== 0)
  17207. {
  17208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  17209. isSuccess = ConfigurationStatus_Accepted;
  17210. }
  17211. else if(strcmp(str, "rts")== 0)
  17212. {
  17213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  17214. isSuccess = ConfigurationStatus_Accepted;
  17215. }
  17216. else if(strcmp(str, "srt")== 0)
  17217. {
  17218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  17219. isSuccess = ConfigurationStatus_Accepted;
  17220. }
  17221. else if(strcmp(str, "str")== 0)
  17222. {
  17223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  17224. isSuccess = ConfigurationStatus_Accepted;
  17225. }
  17226. else if(strcmp(str, "trs")== 0)
  17227. {
  17228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  17229. isSuccess = ConfigurationStatus_Accepted;
  17230. }
  17231. else if(strcmp(str, "tsr")== 0)
  17232. {
  17233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  17234. isSuccess = ConfigurationStatus_Accepted;
  17235. }
  17236. else
  17237. {
  17238. isSuccess = ConfigurationStatus_Rejected;
  17239. }
  17240. }
  17241. else
  17242. {
  17243. isSuccess = ConfigurationStatus_Rejected;
  17244. }
  17245. }
  17246. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  17247. {
  17248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17249. {
  17250. check_ascii = value[0];
  17251. if( (check_ascii < 48) || (check_ascii > 57) )
  17252. {
  17253. isSuccess = ConfigurationStatus_Rejected;
  17254. }
  17255. else
  17256. {
  17257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17258. isSuccess = ConfigurationStatus_Accepted;
  17259. }
  17260. }
  17261. else
  17262. {
  17263. isSuccess = ConfigurationStatus_Rejected;
  17264. }
  17265. }
  17266. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17267. {
  17268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17269. {
  17270. strcpy(str, (const char*)value);
  17271. for(int i = 0; str[i]; i++)
  17272. {
  17273. str[i] = tolower(str[i]);
  17274. }
  17275. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17277. isSuccess = ConfigurationStatus_Accepted;
  17278. }
  17279. else
  17280. {
  17281. isSuccess = ConfigurationStatus_Rejected;
  17282. }
  17283. }
  17284. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17285. {
  17286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17287. {
  17288. strcpy(str, (const char*)value);
  17289. for(int i = 0; str[i]; i++)
  17290. {
  17291. str[i] = tolower(str[i]);
  17292. }
  17293. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17295. isSuccess = ConfigurationStatus_Accepted;
  17296. }
  17297. else
  17298. {
  17299. isSuccess = ConfigurationStatus_Rejected;
  17300. }
  17301. }
  17302. if(strcmp(key, "StopTxnAlignedData") == 0)
  17303. {
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17305. {
  17306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17307. isSuccess = ConfigurationStatus_Accepted;
  17308. }
  17309. else
  17310. {
  17311. isSuccess = ConfigurationStatus_Rejected;
  17312. }
  17313. }
  17314. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17315. {
  17316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17317. {
  17318. check_ascii = value[0];
  17319. if( (check_ascii < 48) || (check_ascii > 57) )
  17320. {
  17321. isSuccess = ConfigurationStatus_Rejected;
  17322. }
  17323. else
  17324. {
  17325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17326. isSuccess = ConfigurationStatus_Accepted;
  17327. }
  17328. }
  17329. else
  17330. {
  17331. isSuccess = ConfigurationStatus_Rejected;
  17332. }
  17333. }
  17334. if(strcmp(key, "StopTxnSampledData") == 0)
  17335. {
  17336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17337. {
  17338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17339. isSuccess = ConfigurationStatus_Accepted;
  17340. }
  17341. else
  17342. {
  17343. isSuccess = ConfigurationStatus_Rejected;
  17344. }
  17345. }
  17346. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17347. {
  17348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17349. {
  17350. check_ascii = value[0];
  17351. if( (check_ascii < 48) || (check_ascii > 57) )
  17352. {
  17353. isSuccess = ConfigurationStatus_Rejected;
  17354. }
  17355. else
  17356. {
  17357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17358. isSuccess = ConfigurationStatus_Accepted;
  17359. }
  17360. }
  17361. else
  17362. {
  17363. isSuccess = ConfigurationStatus_Rejected;
  17364. }
  17365. }
  17366. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17367. {
  17368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17369. {
  17370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17371. isSuccess = ConfigurationStatus_Accepted;
  17372. }
  17373. else
  17374. {
  17375. isSuccess = ConfigurationStatus_Rejected;
  17376. }
  17377. }
  17378. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17379. {
  17380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17381. {
  17382. check_ascii = value[0];
  17383. if( (check_ascii < 48) || (check_ascii > 57) )
  17384. {
  17385. isSuccess = ConfigurationStatus_Rejected;
  17386. }
  17387. else
  17388. {
  17389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17390. isSuccess = ConfigurationStatus_Accepted;
  17391. }
  17392. }
  17393. else
  17394. {
  17395. isSuccess = ConfigurationStatus_Rejected;
  17396. }
  17397. }
  17398. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17399. {
  17400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17401. {
  17402. check_ascii = value[0];
  17403. if( (check_ascii < 48) || (check_ascii > 57) )
  17404. {
  17405. isSuccess = ConfigurationStatus_Rejected;
  17406. }
  17407. else
  17408. {
  17409. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17411. TransactionMessageAttemptsValue = atoi(value);
  17412. isSuccess = ConfigurationStatus_Accepted;
  17413. }
  17414. }
  17415. else
  17416. {
  17417. isSuccess = ConfigurationStatus_Rejected;
  17418. }
  17419. }
  17420. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17421. {
  17422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17423. {
  17424. check_ascii = value[0];
  17425. if( (check_ascii < 48) || (check_ascii > 57) )
  17426. {
  17427. isSuccess = ConfigurationStatus_Rejected;
  17428. }
  17429. else
  17430. {
  17431. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17433. TransactionMessageRetryIntervalValue = atoi(value);
  17434. isSuccess = ConfigurationStatus_Accepted;
  17435. }
  17436. }
  17437. else
  17438. {
  17439. isSuccess = ConfigurationStatus_Rejected;
  17440. }
  17441. }
  17442. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17443. {
  17444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17445. {
  17446. strcpy(str, (const char*)value);
  17447. for(int i = 0; str[i]; i++)
  17448. {
  17449. str[i] = tolower(str[i]);
  17450. }
  17451. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17453. isSuccess = ConfigurationStatus_Accepted;
  17454. }
  17455. else
  17456. {
  17457. isSuccess = ConfigurationStatus_Rejected;
  17458. }
  17459. }
  17460. if(strcmp(key, "WebSocketPingInterval") == 0)
  17461. {
  17462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17463. {
  17464. check_ascii = value[0];
  17465. if( (check_ascii < 48) || (check_ascii > 57) )
  17466. {
  17467. isSuccess = ConfigurationStatus_Rejected;
  17468. }
  17469. else
  17470. {
  17471. if((atoi(value) == 0) || (atoi(value) >= 10))
  17472. {
  17473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17474. isSuccess = ConfigurationStatus_Accepted;
  17475. }
  17476. else
  17477. isSuccess = ConfigurationStatus_Rejected;
  17478. }
  17479. }
  17480. else
  17481. {
  17482. isSuccess = ConfigurationStatus_Rejected;
  17483. }
  17484. }
  17485. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17486. {
  17487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17488. {
  17489. strcpy(str, (const char*)value);
  17490. for(int i = 0; str[i]; i++)
  17491. {
  17492. str[i] = tolower(str[i]);
  17493. }
  17494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17495. isSuccess = ConfigurationStatus_Accepted;
  17496. }
  17497. else
  17498. {
  17499. isSuccess = ConfigurationStatus_Rejected;
  17500. }
  17501. }
  17502. if(strcmp(key, "AuthorizationKey") == 0)
  17503. {
  17504. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17505. {
  17506. strcpy(str, (const char*)value);
  17507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17508. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17509. isSuccess = ConfigurationStatus_Accepted;
  17510. }
  17511. else
  17512. {
  17513. isSuccess = ConfigurationStatus_Rejected;
  17514. }
  17515. }
  17516. if(strcmp(key, "SecurityProfile") == 0)
  17517. {
  17518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17519. {
  17520. check_ascii = value[0];
  17521. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17522. {
  17523. isSuccess = ConfigurationStatus_Rejected;
  17524. }
  17525. else if(check_ascii == 0x33)
  17526. {
  17527. isSuccess = NotSupported;
  17528. }
  17529. else
  17530. {
  17531. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17532. {
  17533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17534. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17535. isSuccess = ConfigurationStatus_Accepted;
  17536. }
  17537. else
  17538. isSuccess = ConfigurationStatus_Rejected;
  17539. }
  17540. }
  17541. else
  17542. {
  17543. isSuccess = ConfigurationStatus_Rejected;
  17544. }
  17545. }
  17546. if(strcmp(key, "DefaultPrice") == 0)
  17547. {
  17548. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17549. {
  17550. strcpy(str, (const char*)value);
  17551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17552. isSuccess = ConfigurationStatus_Accepted;
  17553. }
  17554. else
  17555. {
  17556. isSuccess = ConfigurationStatus_Rejected;
  17557. }
  17558. }
  17559. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17560. {
  17561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17562. {
  17563. strcpy(str, (const char*)value);
  17564. for(int i = 0; str[i]; i++)
  17565. {
  17566. str[i] = tolower(str[i]);
  17567. }
  17568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17569. isSuccess = ConfigurationStatus_Accepted;
  17570. }
  17571. else
  17572. {
  17573. isSuccess = ConfigurationStatus_Rejected;
  17574. }
  17575. }
  17576. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17577. {
  17578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17579. {
  17580. strcpy(str, (const char*)value);
  17581. for(int i = 0; str[i]; i++)
  17582. {
  17583. str[i] = tolower(str[i]);
  17584. }
  17585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17586. isSuccess = ConfigurationStatus_Accepted;
  17587. }
  17588. else
  17589. {
  17590. isSuccess = ConfigurationStatus_Rejected;
  17591. }
  17592. }
  17593. if(strcmp(key, "TimeOffset") == 0)
  17594. {
  17595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17596. {
  17597. strcpy(str, (const char*)value);
  17598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17599. isSuccess = ConfigurationStatus_Accepted;
  17600. }
  17601. else
  17602. {
  17603. isSuccess = ConfigurationStatus_Rejected;
  17604. }
  17605. }
  17606. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17607. {
  17608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17609. {
  17610. strcpy(str, (const char*)value);
  17611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17612. isSuccess = ConfigurationStatus_Accepted;
  17613. }
  17614. else
  17615. {
  17616. isSuccess = ConfigurationStatus_Rejected;
  17617. }
  17618. }
  17619. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17620. {
  17621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17622. {
  17623. strcpy(str, (const char*)value);
  17624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17625. isSuccess = ConfigurationStatus_Accepted;
  17626. }
  17627. else
  17628. {
  17629. isSuccess = ConfigurationStatus_Rejected;
  17630. }
  17631. }
  17632. if(strcmp(key, "SystemUptimeSec") == 0)
  17633. {
  17634. isSuccess = NotSupported;
  17635. }
  17636. if(strcmp(key, "FreeVend") == 0)
  17637. {
  17638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17639. {
  17640. strcpy(str, (const char*)value);
  17641. for(int i = 0; str[i]; i++)
  17642. {
  17643. str[i] = tolower(str[i]);
  17644. }
  17645. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17647. isSuccess = ConfigurationStatus_Accepted;
  17648. }
  17649. else
  17650. {
  17651. isSuccess = ConfigurationStatus_Rejected;
  17652. }
  17653. }
  17654. if(strcmp(key, "FreeVendIdtag") == 0)
  17655. {
  17656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17657. {
  17658. strcpy(str, (const char*)value);
  17659. if(strlen(str) <= 20)
  17660. {
  17661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17662. isSuccess = ConfigurationStatus_Accepted;
  17663. }
  17664. else
  17665. {
  17666. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17667. isSuccess = ConfigurationStatus_Rejected;
  17668. }
  17669. }
  17670. else
  17671. {
  17672. isSuccess = ConfigurationStatus_Rejected;
  17673. }
  17674. }
  17675. if(strcmp(key, "OcppServer") == 0)
  17676. {
  17677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17678. {
  17679. strcpy(str, (const char*)value);
  17680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17681. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17682. isSuccess = ConfigurationStatus_Accepted;
  17683. }
  17684. else
  17685. {
  17686. isSuccess = ConfigurationStatus_Rejected;
  17687. }
  17688. }
  17689. if(strcmp(key, "MaintainServer") == 0)
  17690. {
  17691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17692. {
  17693. strcpy(str, (const char*)value);
  17694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17695. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17696. isSuccess = ConfigurationStatus_Accepted;
  17697. }
  17698. else
  17699. {
  17700. isSuccess = ConfigurationStatus_Rejected;
  17701. }
  17702. }
  17703. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17704. {
  17705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17706. {
  17707. strcpy(str, (const char*)value);
  17708. for(int i = 0; str[i]; i++)
  17709. {
  17710. str[i] = tolower(str[i]);
  17711. }
  17712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17713. isSuccess = ConfigurationStatus_Accepted;
  17714. }
  17715. else
  17716. {
  17717. isSuccess = ConfigurationStatus_Rejected;
  17718. }
  17719. }
  17720. if(strcmp(key, "StatusNotificationInterval") == 0)
  17721. {
  17722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17723. {
  17724. check_ascii = value[0];
  17725. if( (check_ascii < 48) || (check_ascii > 57) )
  17726. {
  17727. isSuccess = ConfigurationStatus_Rejected;
  17728. }
  17729. else
  17730. {
  17731. if((atoi(value) == 0) || (atoi(value) >= 10))
  17732. {
  17733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17734. isSuccess = ConfigurationStatus_Accepted;
  17735. }
  17736. else
  17737. isSuccess = ConfigurationStatus_Rejected;
  17738. }
  17739. }
  17740. else
  17741. {
  17742. isSuccess = ConfigurationStatus_Rejected;
  17743. }
  17744. }
  17745. if(strcmp(key, "PreAuthAmount") == 0)
  17746. {
  17747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17748. {
  17749. check_ascii = value[0];
  17750. if( (check_ascii < 48) || (check_ascii > 57) )
  17751. {
  17752. isSuccess = ConfigurationStatus_Rejected;
  17753. }
  17754. else
  17755. {
  17756. if(atof(value) >= 0)
  17757. {
  17758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17759. isSuccess = ConfigurationStatus_Accepted;
  17760. }
  17761. else
  17762. isSuccess = ConfigurationStatus_Rejected;
  17763. }
  17764. }
  17765. else
  17766. {
  17767. isSuccess = ConfigurationStatus_Rejected;
  17768. }
  17769. }
  17770. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17771. {
  17772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17773. {
  17774. check_ascii = value[0];
  17775. if( (check_ascii < 48) || (check_ascii > 57) )
  17776. {
  17777. isSuccess = ConfigurationStatus_Rejected;
  17778. }
  17779. else
  17780. {
  17781. if(atoi(value) >= 0)
  17782. {
  17783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17784. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17785. isSuccess = ConfigurationStatus_Accepted;
  17786. }
  17787. else
  17788. isSuccess = ConfigurationStatus_Rejected;
  17789. }
  17790. }
  17791. else
  17792. {
  17793. isSuccess = ConfigurationStatus_Rejected;
  17794. }
  17795. }
  17796. if(strcmp(key, "PowerSharingServerIP") == 0)
  17797. {
  17798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17799. {
  17800. strcpy(str, (const char*)value);
  17801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17802. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17803. isSuccess = ConfigurationStatus_Accepted;
  17804. }
  17805. else
  17806. {
  17807. isSuccess = ConfigurationStatus_Rejected;
  17808. }
  17809. }
  17810. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17811. {
  17812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17813. {
  17814. strcpy(str, (const char*)value);
  17815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17816. isSuccess = ConfigurationStatus_Accepted;
  17817. }
  17818. else
  17819. {
  17820. isSuccess = ConfigurationStatus_Rejected;
  17821. }
  17822. }
  17823. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17824. {
  17825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17826. {
  17827. if(atoi(value) > modelnameInfo.ratedPower)
  17828. {
  17829. isSuccess = ConfigurationStatus_Rejected;
  17830. }
  17831. else{
  17832. strcpy(str, (const char*)value);
  17833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17834. isSuccess = ConfigurationStatus_Accepted;
  17835. }
  17836. }
  17837. else
  17838. {
  17839. isSuccess = ConfigurationStatus_Rejected;
  17840. }
  17841. }
  17842. #if 0
  17843. //For OCPP Test Case
  17844. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17845. {
  17846. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17847. {
  17848. strcpy(str, (const char*)value);
  17849. for(int i = 0; str[i]; i++)
  17850. {
  17851. str[i] = tolower(str[i]);
  17852. }
  17853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17854. isSuccess = ConfigurationStatus_Accepted;
  17855. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17856. }
  17857. else
  17858. {
  17859. isSuccess = ConfigurationStatus_Rejected;
  17860. }
  17861. }
  17862. #endif
  17863. #if 1
  17864. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17865. {
  17866. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17867. {
  17868. strcpy(str, (const char*)value);
  17869. for(int i = 0; str[i]; i++)
  17870. {
  17871. str[i] = tolower(str[i]);
  17872. }
  17873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17874. isSuccess = ConfigurationStatus_Accepted;
  17875. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17876. }
  17877. else
  17878. {
  17879. isSuccess = ConfigurationStatus_Rejected;
  17880. }
  17881. }
  17882. #endif
  17883. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17884. {
  17885. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17886. {
  17887. check_ascii = value[0];
  17888. if( (check_ascii < 48) || (check_ascii > 57) )
  17889. {
  17890. isSuccess = ConfigurationStatus_Rejected;
  17891. }
  17892. else
  17893. {
  17894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17895. isSuccess = ConfigurationStatus_Accepted;
  17896. }
  17897. }
  17898. else
  17899. {
  17900. isSuccess = ConfigurationStatus_Rejected;
  17901. }
  17902. }
  17903. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17904. {
  17905. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17906. {
  17907. check_ascii = value[0];
  17908. if( (check_ascii < 48) || (check_ascii > 57) )
  17909. {
  17910. isSuccess = ConfigurationStatus_Rejected;
  17911. }
  17912. else
  17913. {
  17914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17915. isSuccess = ConfigurationStatus_Accepted;
  17916. }
  17917. }
  17918. else
  17919. {
  17920. isSuccess = ConfigurationStatus_Rejected;
  17921. }
  17922. }
  17923. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17924. {
  17925. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17926. {
  17927. strcpy(str, (const char*)value);
  17928. for(int i = 0; str[i]; i++)
  17929. {
  17930. str[i] = tolower(str[i]);
  17931. }
  17932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17933. isSuccess = ConfigurationStatus_Accepted;
  17934. }
  17935. else
  17936. {
  17937. isSuccess = ConfigurationStatus_Rejected;
  17938. }
  17939. }
  17940. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17941. {
  17942. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17943. {
  17944. check_ascii = value[0];
  17945. if( (check_ascii < 48) || (check_ascii > 57) )
  17946. {
  17947. isSuccess = ConfigurationStatus_Rejected;
  17948. }
  17949. else
  17950. {
  17951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17952. isSuccess = ConfigurationStatus_Accepted;
  17953. }
  17954. }
  17955. else
  17956. {
  17957. isSuccess = ConfigurationStatus_Rejected;
  17958. }
  17959. }
  17960. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17961. {
  17962. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17963. {
  17964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17965. isSuccess = ConfigurationStatus_Accepted;
  17966. }
  17967. else
  17968. {
  17969. isSuccess = ConfigurationStatus_Rejected;
  17970. }
  17971. }
  17972. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17973. {
  17974. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17975. {
  17976. check_ascii = value[0];
  17977. if( (check_ascii < 48) || (check_ascii > 57) )
  17978. {
  17979. isSuccess = ConfigurationStatus_Rejected;
  17980. }
  17981. else
  17982. {
  17983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17984. isSuccess = ConfigurationStatus_Accepted;
  17985. }
  17986. }
  17987. else
  17988. {
  17989. isSuccess = ConfigurationStatus_Rejected;
  17990. }
  17991. }
  17992. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17993. {
  17994. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17995. {
  17996. strcpy(str, (const char*)value);
  17997. for(int i = 0; str[i]; i++)
  17998. {
  17999. str[i] = tolower(str[i]);
  18000. }
  18001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18002. isSuccess = ConfigurationStatus_Accepted;
  18003. }
  18004. else
  18005. {
  18006. isSuccess = ConfigurationStatus_Rejected;
  18007. }
  18008. }
  18009. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18010. {
  18011. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18012. {
  18013. check_ascii = value[0];
  18014. if( (check_ascii < 48) || (check_ascii > 57) )
  18015. {
  18016. isSuccess = ConfigurationStatus_Rejected;
  18017. }
  18018. else
  18019. {
  18020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18021. isSuccess = ConfigurationStatus_Accepted;
  18022. }
  18023. }
  18024. else
  18025. {
  18026. isSuccess = ConfigurationStatus_Rejected;
  18027. }
  18028. }
  18029. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18030. return isSuccess;
  18031. }
  18032. int TransactionMessageAttemptsGet(void)
  18033. {
  18034. return TransactionMessageAttemptsValue;
  18035. }
  18036. int FirstHeartBeatResponse(void)
  18037. {
  18038. return FirstHeartBeat;
  18039. }
  18040. int TransactionMessageRetryIntervalGet(void)
  18041. {
  18042. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18043. }
  18044. int ReadHttpStatus(int sock)
  18045. {
  18046. //char c;
  18047. char buff[1024]="",*ptr=buff+1;
  18048. int bytes_received, status;
  18049. DEBUG_INFO("Begin Response ..\n");
  18050. while((bytes_received = recv(sock, ptr, 1, 0))){
  18051. if(bytes_received==-1){
  18052. perror("ReadHttpStatus");
  18053. exit(1);
  18054. }
  18055. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18056. ptr++;
  18057. }
  18058. *ptr=0;
  18059. ptr=buff+1;
  18060. sscanf(ptr,"%*s %d ", &status);
  18061. DEBUG_INFO("%s\n",ptr);
  18062. DEBUG_INFO("status=%d\n",status);
  18063. DEBUG_INFO("End Response ..\n");
  18064. return (bytes_received>0)?status:0;
  18065. }
  18066. //the only filed that it parsed is 'Content-Length'
  18067. int ParseHeader(int sock)
  18068. {
  18069. //char c;
  18070. char buff[1024]="",*ptr=buff+4;
  18071. int bytes_received;
  18072. DEBUG_INFO("Begin HEADER ..\n");
  18073. while((bytes_received = recv(sock, ptr, 1, 0))){
  18074. if(bytes_received==-1){
  18075. perror("Parse Header");
  18076. exit(1);
  18077. }
  18078. if(
  18079. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18080. (ptr[-1]=='\r') && (*ptr=='\n' )
  18081. ) break;
  18082. ptr++;
  18083. }
  18084. *ptr=0;
  18085. ptr=buff+4;
  18086. //printf("%s",ptr);
  18087. if(bytes_received){
  18088. ptr=strstr(ptr,"Content-Length:");
  18089. if(ptr){
  18090. sscanf(ptr,"%*s %d",&bytes_received);
  18091. }else
  18092. bytes_received=-1; //unknown size
  18093. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18094. }
  18095. DEBUG_INFO("End HEADER ..\n");
  18096. return bytes_received ;
  18097. }
  18098. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18099. {
  18100. int result = TRUE;
  18101. char rmFileCmd[100]={0};
  18102. char FilePath[100]={0};
  18103. char ftpbuf[200];
  18104. int systemresult;
  18105. sprintf(FilePath,"/mnt/%s",filename);
  18106. system("ping 8.8.8.8 &");
  18107. if((access(FilePath,F_OK))!=-1)
  18108. {
  18109. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18110. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18111. system(rmFileCmd);
  18112. }
  18113. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18114. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18115. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18116. systemresult = system(ftpbuf);
  18117. if(systemresult != 0)
  18118. {
  18119. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18120. result = FALSE;
  18121. }
  18122. system("pkill ping");
  18123. return result;
  18124. }
  18125. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18126. {
  18127. int result = TRUE;
  18128. char rmFileCmd[100]={0};
  18129. char FilePath[100]={0};
  18130. char ftpbuf[200];
  18131. int systemresult;
  18132. sprintf(FilePath,"/mnt/%s",filename);
  18133. system("ping 8.8.8.8 &");
  18134. if((access(FilePath,F_OK))!=-1)
  18135. {
  18136. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18137. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18138. system(rmFileCmd);
  18139. }
  18140. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18141. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18142. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18143. systemresult = system(ftpbuf);
  18144. if(systemresult != 0)
  18145. {
  18146. DEBUG_WARN("scp error!\n");
  18147. result = FALSE;
  18148. }
  18149. system("pkill ping");
  18150. return result;
  18151. }
  18152. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18153. {
  18154. int result = TRUE;
  18155. char rmFileCmd[100]={0};
  18156. char FilePath[100]={0};
  18157. char ftpbuf[200];
  18158. int systemresult;
  18159. sprintf(FilePath,"/mnt/%s",filename);
  18160. system("ping 8.8.8.8 &");
  18161. if((access(FilePath,F_OK))!=-1)
  18162. {
  18163. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18164. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18165. system(rmFileCmd);
  18166. }
  18167. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18168. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18169. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18170. systemresult = system(ftpbuf);
  18171. if(systemresult != 0)
  18172. {
  18173. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18174. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18175. systemresult = system(ftpbuf);
  18176. if(systemresult != 0)
  18177. {
  18178. DEBUG_WARN("FTP download fail!\n");
  18179. result = FALSE;
  18180. }
  18181. }
  18182. system("pkill ping");
  18183. return result;
  18184. }
  18185. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18186. {
  18187. char rmFileCmd[100]={0};
  18188. char FilePath[100]={0};
  18189. char buf[512];
  18190. int systemresult = 0;
  18191. //DEBUG_INFO("filename=%s\n",filename);
  18192. //DEBUG_INFO("url=%s\n",url);
  18193. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18194. if((access(FilePath,F_OK))!=-1)
  18195. {
  18196. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18197. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18198. system(rmFileCmd);
  18199. }
  18200. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18201. if(fp == NULL)
  18202. {
  18203. DEBUG_INFO("log is NULL\n");
  18204. return FALSE;
  18205. }
  18206. else
  18207. {
  18208. fprintf(fp, "%s\n", url);
  18209. fprintf(fp, "%s\n", filename);
  18210. fclose(fp);
  18211. }
  18212. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18213. if(phpFP == NULL)
  18214. {
  18215. DEBUG_INFO("PHP upload fail.\n");
  18216. return FALSE;
  18217. }
  18218. else
  18219. {
  18220. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18221. {
  18222. if(strstr(buf, "result") != NULL)
  18223. {
  18224. sscanf(buf, "result: %d", &systemresult);
  18225. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18226. }
  18227. }
  18228. pclose(phpFP);
  18229. }
  18230. if(systemresult != 1)
  18231. {
  18232. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18233. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18234. if(phpFP == NULL)
  18235. {
  18236. DEBUG_WARN("PHP PUT upload fail.\n");
  18237. return FALSE;
  18238. }
  18239. else
  18240. {
  18241. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18242. {
  18243. if(strstr(buf, "result") != NULL)
  18244. {
  18245. sscanf(buf, "result: %d", &systemresult);
  18246. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18247. }
  18248. }
  18249. pclose(phpFP);
  18250. }
  18251. }
  18252. if(systemresult != 1)
  18253. {
  18254. DEBUG_WARN("PHP PUT upload fail.\n");
  18255. return FALSE;
  18256. }
  18257. return TRUE;
  18258. }
  18259. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18260. {
  18261. int result = FALSE;
  18262. char ftpbuf[200];
  18263. int systemresult;
  18264. /*
  18265. // Domaind name transfer to IP address
  18266. struct hostent* server;
  18267. char *IPbuffer;
  18268. server = gethostbyname(location);
  18269. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18270. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18271. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18272. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18273. systemresult = system(ftpbuf);
  18274. if(systemresult != 0)
  18275. {
  18276. DEBUG_INFO("ftpput error!\n");
  18277. }
  18278. else
  18279. {
  18280. result = TRUE;
  18281. DEBUG_INFO("ftpput OK!\n");
  18282. }
  18283. return result;
  18284. }
  18285. int GetOcppServerURL()
  18286. {
  18287. int result = FALSE;
  18288. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18289. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18290. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18291. struct yuarel url;
  18292. char urlStr[512];
  18293. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18294. {
  18295. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18296. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18297. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18298. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18299. if(yuarel_parse(&url, urlStr) != -1)
  18300. {
  18301. sprintf(OcppProtocol, "%s", url.scheme);
  18302. sprintf(OcppHost, "%s", url.host);
  18303. if(url.path == NULL)
  18304. OcppTempPath[0] = '\0';
  18305. else
  18306. {
  18307. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18308. {
  18309. sprintf(OcppTempPath, "%s/", url.path);
  18310. }
  18311. else
  18312. {
  18313. sprintf(OcppTempPath, "%s", url.path);
  18314. }
  18315. }
  18316. if(url.port == 0)
  18317. {
  18318. if(strcmp(OcppProtocol, "wss") == 0)
  18319. OcppPort = 443;
  18320. else
  18321. OcppPort = 80;
  18322. }
  18323. else
  18324. OcppPort = url.port;
  18325. result = TRUE;
  18326. }
  18327. }
  18328. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18329. {
  18330. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18331. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18332. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18333. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18334. if(yuarel_parse(&url, urlStr) != -1)
  18335. {
  18336. sprintf(OcppProtocol, "%s", url.scheme);
  18337. sprintf(OcppHost, "%s", url.host);
  18338. if(url.path == NULL)
  18339. OcppTempPath[0] = '\0';
  18340. else
  18341. sprintf(OcppTempPath, "%s", url.path);
  18342. if(url.port == 0)
  18343. {
  18344. if(strcmp(OcppProtocol, "wss") == 0)
  18345. OcppPort = 443;
  18346. else
  18347. OcppPort = 80;
  18348. }
  18349. else
  18350. OcppPort = url.port;
  18351. result = TRUE;
  18352. }
  18353. }
  18354. else
  18355. {
  18356. strcpy(OcppHost,"");
  18357. }
  18358. return result;
  18359. }
  18360. int GetOcppPath()
  18361. {
  18362. int result = FALSE;
  18363. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18364. {
  18365. if(OcppTempPath == NULL)
  18366. {
  18367. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18368. }
  18369. else
  18370. {
  18371. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18372. }
  18373. result = TRUE;
  18374. goto End;
  18375. }
  18376. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18377. {
  18378. if(OcppTempPath == NULL)
  18379. {
  18380. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18381. }
  18382. else
  18383. {
  18384. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18385. }
  18386. result = TRUE;
  18387. goto End;
  18388. }
  18389. else
  18390. {
  18391. strcpy(OcppPath,"");
  18392. }
  18393. End:
  18394. return result;
  18395. }
  18396. int GetOcppPort()
  18397. {
  18398. return OcppPort;
  18399. }
  18400. int GetOcppConnStatus(void)
  18401. {
  18402. return ShmOCPP16Data->OcppConnStatus;
  18403. }
  18404. void SetOcppConnStatus(uint8_t status)
  18405. {
  18406. ShmOCPP16Data->OcppConnStatus = status;
  18407. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18408. }
  18409. int GetHeartBeatWithNOResponse(void)
  18410. {
  18411. return HeartBeatWithNOResponse;
  18412. }
  18413. void SetHeartBeatWithNOResponse(void)
  18414. {
  18415. HeartBeatWithNOResponse = 0;
  18416. }
  18417. void GetStartTransactionIdTag(int gun_index)
  18418. {
  18419. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18420. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18421. }
  18422. int GetStartTransactionId(int gun_index)
  18423. {
  18424. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18425. }
  18426. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18427. {
  18428. char ch;
  18429. FILE *fptr1;
  18430. int temptransactionId;
  18431. char str[100]={0};
  18432. temptransactionId = 0;
  18433. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18434. {
  18435. DEBUG_INFO("IdTag is empty.\n");
  18436. return temptransactionId;
  18437. }
  18438. /*------ Read the file ----------------*/
  18439. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18440. if (!fptr1)
  18441. {
  18442. DEBUG_INFO("QueueTransactionId file open error.\n");
  18443. //printf(" File not found or unable to open the input file!!\n");
  18444. return temptransactionId;
  18445. }
  18446. ch=fgetc(fptr1);
  18447. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18448. rewind(fptr1);
  18449. if(ch!=EOF)
  18450. {
  18451. // printf("%c",ch);
  18452. while (fgets(str, 100, fptr1) != NULL)
  18453. {
  18454. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18455. if(str[0]=='\0')
  18456. {
  18457. break;
  18458. }
  18459. char *revbuf[8] = {0}; // Variable store string split
  18460. int num = 0;// Quantity after string split
  18461. DEBUG_INFO("Transaction queue data= %s\n", str);
  18462. splitstring(str,",",revbuf,&num); // String split
  18463. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18464. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18465. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18466. DEBUG_INFO("------------------------------\n");
  18467. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18468. {
  18469. if(isStopTransaction)
  18470. {
  18471. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18472. {
  18473. temptransactionId = atoi(revbuf[2]);
  18474. //break;
  18475. }
  18476. }
  18477. else
  18478. {
  18479. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18480. {
  18481. temptransactionId = atoi(revbuf[2]);
  18482. //break;
  18483. }
  18484. }
  18485. }
  18486. }
  18487. }
  18488. else
  18489. DEBUG_INFO("EOF\n");
  18490. fclose(fptr1);
  18491. /*------- End of reading ---------------*/
  18492. return temptransactionId;
  18493. }
  18494. void SetTransactionIdZero(int transactionId)
  18495. {
  18496. char ch;
  18497. FILE *fptr1, *fptr2;
  18498. int temptransactionId = 0;
  18499. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18500. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18501. if (!fptr1)
  18502. {
  18503. //printf(" File not found or unable to open the input file!!\n");
  18504. return ;
  18505. }
  18506. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18507. if (!fptr2)
  18508. {
  18509. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18510. fclose(fptr1);
  18511. return ;
  18512. }
  18513. ch=fgetc(fptr1);
  18514. rewind(fptr1);
  18515. if(ch!=EOF)
  18516. {
  18517. // copy all contents to the temporary file except the specific line
  18518. while (fgets(str, 100, fptr1) != NULL)
  18519. {
  18520. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18521. if(str[0]=='\0')
  18522. {
  18523. break;
  18524. }
  18525. char *revbuf[8] = {0};
  18526. int num = 0;
  18527. strcpy(strtemp, str);
  18528. splitstring(str,",",revbuf,&num);
  18529. if(revbuf[2][0] != '\0')
  18530. {
  18531. temptransactionId = atoi(revbuf[2]);
  18532. if(transactionId != temptransactionId)
  18533. {
  18534. fprintf(fptr2, "%s\n", strtemp);
  18535. }
  18536. }
  18537. }
  18538. }
  18539. fclose(fptr1);
  18540. fclose(fptr2);
  18541. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18542. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18543. /*------ Read the file ----------------*/
  18544. }
  18545. int InternetDisconnect(void)
  18546. {
  18547. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18548. }
  18549. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18550. void storeTempStopTransaction(int gun_index)
  18551. {
  18552. char guid[37]={0};
  18553. int tempIndex = 0;
  18554. char TempStopTransaction[256];
  18555. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18556. DEBUG_INFO("storeTempStopTransaction...\n");
  18557. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18558. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18559. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18562. {
  18563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18564. {
  18565. tempIndex = ((gun_index==2) ? 1: 0);
  18566. }
  18567. else
  18568. {
  18569. tempIndex = gun_index;
  18570. }
  18571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18572. {
  18573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18574. {
  18575. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18576. }
  18577. }// END OF CHAdeMO_QUANTITY
  18578. }
  18579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18580. {
  18581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18582. {
  18583. tempIndex = ((gun_index==2) ? 1: 0);
  18584. }
  18585. else
  18586. {
  18587. tempIndex = gun_index;
  18588. }
  18589. for (int index = 0; index < CCS_QUANTITY; index++)
  18590. {
  18591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18592. {
  18593. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18594. }
  18595. }// END OF CCS_QUANTITY
  18596. }
  18597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18598. {
  18599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18600. {
  18601. tempIndex = ((gun_index==2) ? 1: 0);
  18602. }
  18603. else
  18604. {
  18605. tempIndex = gun_index;
  18606. }
  18607. for (int index = 0; index < GB_QUANTITY; index++)
  18608. {
  18609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18610. {
  18611. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18612. }
  18613. }// END OF GB_QUANTITY
  18614. }
  18615. else if(gunType[gun_index] == GUN_TYPE_DO)
  18616. {
  18617. tempIndex = gun_index;
  18618. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18619. {
  18620. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18621. {
  18622. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18623. }
  18624. }
  18625. }
  18626. else
  18627. {
  18628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18629. {
  18630. tempIndex = 2;
  18631. }
  18632. else
  18633. {
  18634. tempIndex = gun_index;
  18635. }
  18636. for (int index = 0; index < AC_QUANTITY; index++)
  18637. {
  18638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18639. {
  18640. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18641. }
  18642. }// END OF AC_QUANTITY
  18643. }
  18644. //Stop Transaction Time
  18645. struct timeval tmnow;
  18646. struct tm *tm;
  18647. char buf[28];//, usec_buf[6];
  18648. gettimeofday(&tmnow, NULL);
  18649. time_t t;
  18650. t = time(NULL);
  18651. /*UTC time and date*/
  18652. tm = gmtime(&t);
  18653. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18655. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18657. random_uuid(guid);
  18658. /***********************************transactionData******************************************************/
  18659. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18661. //=================================
  18662. //1. Transaction_Begin
  18663. //=================================
  18664. //============================== Energy.Active.Import.Interval ===========================================
  18665. //=================================
  18666. //2. Transaction_End
  18667. //=================================
  18668. //2.1====================================== Current.Import L1 ==============================================
  18669. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18670. {
  18671. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18672. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18673. {
  18674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18675. {
  18676. tempIndex = ((gun_index==2) ? 1: 0);
  18677. }
  18678. else
  18679. {
  18680. tempIndex = gun_index;
  18681. }
  18682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18683. {
  18684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18685. {
  18686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18687. }
  18688. }// End of for CHAdeMO_QUANTITY
  18689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18690. }
  18691. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18692. {
  18693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18694. {
  18695. tempIndex = ((gun_index==2) ? 1: 0);
  18696. }
  18697. else
  18698. {
  18699. tempIndex = gun_index;
  18700. }
  18701. for (int index = 0; index < CCS_QUANTITY; index++)
  18702. {
  18703. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18704. {
  18705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18706. }
  18707. }// End of for CCS_QUANTITY
  18708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18709. }
  18710. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18711. {
  18712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18713. {
  18714. tempIndex = ((gun_index==2) ? 1: 0);
  18715. }
  18716. else
  18717. {
  18718. tempIndex = gun_index;
  18719. }
  18720. for (int index = 0; index < GB_QUANTITY; index++)
  18721. {
  18722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18723. {
  18724. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18725. }
  18726. }// End of for GB_QUANTITY
  18727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18728. }
  18729. else if(gunType[gun_index] == GUN_TYPE_DO)
  18730. {
  18731. tempIndex = gun_index;
  18732. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18733. {
  18734. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18735. {
  18736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18737. }
  18738. }
  18739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18740. }
  18741. else
  18742. {
  18743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18744. {
  18745. tempIndex = 2;
  18746. }
  18747. else
  18748. {
  18749. tempIndex = gun_index;
  18750. }
  18751. for (int index = 0; index < AC_QUANTITY; index++)
  18752. {
  18753. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18754. {
  18755. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18756. }
  18757. }// End of for AC_QUANTITY
  18758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18759. }
  18760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18763. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18766. }
  18767. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18768. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18769. {
  18770. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18771. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18772. {
  18773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18774. {
  18775. tempIndex = ((gun_index==2) ? 1: 0);
  18776. }
  18777. else
  18778. {
  18779. tempIndex = gun_index;
  18780. }
  18781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18782. {
  18783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18784. {
  18785. 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
  18786. }
  18787. }// END OF CHAdeMO_QUANTITY
  18788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18789. }
  18790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18791. {
  18792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18793. {
  18794. tempIndex = ((gun_index==2) ? 1: 0);
  18795. }
  18796. else
  18797. {
  18798. tempIndex = gun_index;
  18799. }
  18800. for (int index = 0; index < CCS_QUANTITY; index++)
  18801. {
  18802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18803. {
  18804. 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
  18805. }
  18806. }// END OF CCS_QUANTITY
  18807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18808. }
  18809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18810. {
  18811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18812. {
  18813. tempIndex = ((gun_index==2) ? 1: 0);
  18814. }
  18815. else
  18816. {
  18817. tempIndex = gun_index;
  18818. }
  18819. for (int index = 0; index < GB_QUANTITY; index++)
  18820. {
  18821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18822. {
  18823. 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
  18824. }
  18825. }// END OF GB_QUANTITY
  18826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18827. }
  18828. else if(gunType[gun_index] == GUN_TYPE_DO)
  18829. {
  18830. tempIndex = gun_index;
  18831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18832. {
  18833. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18834. {
  18835. 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
  18836. }
  18837. }
  18838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18839. }
  18840. else
  18841. {
  18842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18843. {
  18844. tempIndex = 2;
  18845. }
  18846. else
  18847. {
  18848. tempIndex = gun_index;
  18849. }
  18850. for (int index = 0; index < AC_QUANTITY; index++)
  18851. {
  18852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18853. {
  18854. 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
  18855. }
  18856. }// END OF AC_QUANTITY
  18857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18858. }
  18859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18862. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18865. }
  18866. //2.3====================================== Power.Active.Import =========================================
  18867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18868. {
  18869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18871. {
  18872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18873. {
  18874. tempIndex = ((gun_index==2) ? 1: 0);
  18875. }
  18876. else
  18877. {
  18878. tempIndex = gun_index;
  18879. }
  18880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18881. {
  18882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18883. {
  18884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18885. }
  18886. } // End for CHAdeMO_QUANTITY
  18887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18888. }
  18889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18890. {
  18891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18892. {
  18893. tempIndex = ((gun_index==2) ? 1: 0);
  18894. }
  18895. else
  18896. {
  18897. tempIndex = gun_index;
  18898. }
  18899. for (int index = 0; index < CCS_QUANTITY; index++)
  18900. {
  18901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18902. {
  18903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18904. }
  18905. } // END for CCS_QUANTITY
  18906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18907. }
  18908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18909. {
  18910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18911. {
  18912. tempIndex = ((gun_index==2) ? 1: 0);
  18913. }
  18914. else
  18915. {
  18916. tempIndex = gun_index;
  18917. }
  18918. for (int index = 0; index < GB_QUANTITY; index++)
  18919. {
  18920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18921. {
  18922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18923. }
  18924. }// END for GB_QUANTITY
  18925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18926. }
  18927. else if(gunType[gun_index] == GUN_TYPE_DO)
  18928. {
  18929. tempIndex = gun_index;
  18930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18931. {
  18932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18933. {
  18934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18935. }
  18936. }
  18937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18938. }
  18939. else
  18940. {
  18941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18942. {
  18943. tempIndex = 2;
  18944. }
  18945. else
  18946. {
  18947. tempIndex = gun_index;
  18948. }
  18949. for (int index = 0; index < AC_QUANTITY; index++)
  18950. {
  18951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18952. {
  18953. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18954. }
  18955. } // END for AC_QUANTITY
  18956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18957. }
  18958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18961. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18964. }
  18965. //2.4====================================== Voltage L1 ====================================================
  18966. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18967. {
  18968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18970. {
  18971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18972. {
  18973. tempIndex = ((gun_index==2) ? 1: 0);
  18974. }
  18975. else
  18976. {
  18977. tempIndex = gun_index;
  18978. }
  18979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18980. {
  18981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18982. {
  18983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18984. }
  18985. } // END OF FOR CHAdeMO_QUANTITY
  18986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18987. }
  18988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18989. {
  18990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18991. {
  18992. tempIndex = ((gun_index==2) ? 1: 0);
  18993. }
  18994. else
  18995. {
  18996. tempIndex = gun_index;
  18997. }
  18998. for (int index = 0; index < CCS_QUANTITY; index++)
  18999. {
  19000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19001. {
  19002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19003. }
  19004. } // END OF FOR CCS_QUANTITY
  19005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19006. }
  19007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19008. {
  19009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19010. {
  19011. tempIndex = ((gun_index==2) ? 1: 0);
  19012. }
  19013. else
  19014. {
  19015. tempIndex = gun_index;
  19016. }
  19017. for (int index = 0; index < GB_QUANTITY; index++)
  19018. {
  19019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19020. {
  19021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19022. }
  19023. } // END OF FOR GB_QUANTITY
  19024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19025. }
  19026. else if(gunType[gun_index] == GUN_TYPE_DO)
  19027. {
  19028. tempIndex = gun_index;
  19029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19030. {
  19031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19032. {
  19033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19034. }
  19035. }
  19036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19037. }
  19038. else
  19039. {
  19040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19041. {
  19042. tempIndex = 2;
  19043. }
  19044. else
  19045. {
  19046. tempIndex = gun_index;
  19047. }
  19048. for (int index = 0; index < AC_QUANTITY; index++)
  19049. {
  19050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19051. {
  19052. 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
  19053. }
  19054. } // END OF FOR AC_QUANTITY
  19055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19056. }
  19057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19060. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19063. }
  19064. //2.5============================================== End SoC =========================================================
  19065. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19066. {
  19067. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19068. 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))
  19069. {
  19070. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19071. {
  19072. tempIndex = ((gun_index==2) ? 1: 0);
  19073. }
  19074. else
  19075. {
  19076. tempIndex = gun_index;
  19077. }
  19078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19079. {
  19080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19081. {
  19082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19083. {
  19084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19085. }
  19086. }
  19087. }
  19088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19089. {
  19090. for (int index = 0; index < CCS_QUANTITY; index++)
  19091. {
  19092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19093. {
  19094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19095. }
  19096. }
  19097. }
  19098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19099. {
  19100. for (int index = 0; index < GB_QUANTITY; index++)
  19101. {
  19102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19103. {
  19104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19105. }
  19106. }
  19107. }
  19108. else if(gunType[gun_index] == GUN_TYPE_DO)
  19109. {
  19110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19111. {
  19112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19113. {
  19114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19115. }
  19116. }
  19117. }
  19118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19124. } // END FOR DC CASE
  19125. }
  19126. //2.6====================================== Current.Import L2 ==============================================
  19127. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19128. {
  19129. // AC 3 phase L2 current
  19130. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19131. {
  19132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19133. {
  19134. tempIndex = 2;
  19135. }
  19136. else
  19137. {
  19138. tempIndex = gun_index;
  19139. }
  19140. for (int index = 0; index < AC_QUANTITY; index++)
  19141. {
  19142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19143. {
  19144. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19145. }
  19146. }// End of for AC_QUANTITY
  19147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19148. }
  19149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19154. }
  19155. //2.7====================================== Current.Import L3 ==============================================
  19156. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19157. {
  19158. // AC 3 phase L3 current
  19159. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19160. {
  19161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19162. {
  19163. tempIndex = 2;
  19164. }
  19165. else
  19166. {
  19167. tempIndex = gun_index;
  19168. }
  19169. for (int index = 0; index < AC_QUANTITY; index++)
  19170. {
  19171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19172. {
  19173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19174. }
  19175. }// End of for AC_QUANTITY
  19176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19177. }
  19178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  19182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19183. }
  19184. //2.9====================================== Voltage L2 ====================================================
  19185. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19186. {
  19187. // AC 3 phase L2 volatge
  19188. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19189. {
  19190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19191. {
  19192. tempIndex = 2;
  19193. }
  19194. else
  19195. {
  19196. tempIndex = gun_index;
  19197. }
  19198. for (int index = 0; index < AC_QUANTITY; index++)
  19199. {
  19200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19201. {
  19202. 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
  19203. }
  19204. } // END OF FOR AC_QUANTITY
  19205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  19206. }
  19207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  19209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  19210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  19211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19212. }
  19213. //2.10====================================== Voltage L3 ====================================================
  19214. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19215. {
  19216. // AC 3 phase L3 volatge
  19217. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19218. {
  19219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19220. {
  19221. tempIndex = 2;
  19222. }
  19223. else
  19224. {
  19225. tempIndex = gun_index;
  19226. }
  19227. for (int index = 0; index < AC_QUANTITY; index++)
  19228. {
  19229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19230. {
  19231. 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
  19232. }
  19233. } // END OF FOR AC_QUANTITY
  19234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  19235. }
  19236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  19238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  19239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  19240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19241. }
  19242. //====================== Start SoC ================================
  19243. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19244. {
  19245. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19246. 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))
  19247. {
  19248. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19249. {
  19250. tempIndex = ((gun_index==2) ? 1: 0);
  19251. }
  19252. else
  19253. {
  19254. tempIndex = gun_index;
  19255. }
  19256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19257. {
  19258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19259. {
  19260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19261. {
  19262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  19263. }
  19264. }
  19265. }
  19266. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19267. {
  19268. for (int index = 0; index < CCS_QUANTITY; index++)
  19269. {
  19270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19271. {
  19272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19273. }
  19274. }
  19275. }
  19276. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19277. {
  19278. for (int index = 0; index < GB_QUANTITY; index++)
  19279. {
  19280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19281. {
  19282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19283. }
  19284. }
  19285. }
  19286. else if(gunType[gun_index] == GUN_TYPE_DO)
  19287. {
  19288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19289. {
  19290. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19291. {
  19292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19293. }
  19294. }
  19295. }
  19296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19302. } // END FOR DC CASE
  19303. }
  19304. //======================================== Message create ==============================================
  19305. json_object *StopTransaction = json_object_new_object();
  19306. json_object *transactionDatas = json_object_new_array();
  19307. json_object *sampledValues = json_object_new_array();
  19308. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19309. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19310. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19311. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19312. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19313. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19314. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19315. {
  19316. json_object *transactionData = json_object_new_object();
  19317. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19318. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19319. {
  19320. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19321. {
  19322. json_object *sampledValue = json_object_new_object();
  19323. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19324. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19325. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19326. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19327. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19328. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19329. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19330. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19331. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19332. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19333. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19334. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19335. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19336. json_object_array_add(sampledValues, sampledValue);
  19337. }
  19338. }
  19339. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19340. json_object_array_add(transactionDatas, transactionData);
  19341. }
  19342. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19343. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19344. ,MESSAGE_TYPE_CALL
  19345. ,guid
  19346. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19347. json_object_put(StopTransaction);
  19348. // Check File "TempStopTransaction" Exist
  19349. if((access(TempStopTransaction,F_OK))!=-1)
  19350. {
  19351. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19352. fclose(fopen(TempStopTransaction, "w"));
  19353. }
  19354. else
  19355. {
  19356. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19357. FILE *log = fopen(TempStopTransaction, "w+");
  19358. if(log == NULL)
  19359. {
  19360. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19361. return ;
  19362. }
  19363. else
  19364. {
  19365. fclose(log);
  19366. }
  19367. }
  19368. //Add TempStopTransaction | Update TempStopTransaction
  19369. // open file for writing
  19370. FILE *outfile;
  19371. outfile = fopen (TempStopTransaction, "a");
  19372. //DEBUG_INFO("data = %s\n", queuedata);
  19373. fputs(queuedata, outfile);
  19374. fputs("\n", outfile);
  19375. fclose (outfile);
  19376. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19377. OCPP_updatePeriodEnergy(gun_index);
  19378. }
  19379. void checkTempStopTransaction(int gun_index)
  19380. {
  19381. FILE *fptr1;
  19382. char ch;
  19383. char str[QUEUE_MESSAGE_LENGTH]={0};
  19384. char guid[37]={0};
  19385. char tempdata[65]={0};
  19386. char connectorStr[2]={0};
  19387. char TempStopTransaction[256];
  19388. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19389. fptr1 = fopen(TempStopTransaction, "r");
  19390. //TempStopTransaction格式: 槍號,StopTransaction封包
  19391. if (!fptr1)
  19392. {
  19393. //printf(" File not found or unable to open the input file!!\n");
  19394. return ;
  19395. }
  19396. ch=fgetc(fptr1);
  19397. //printf(" Now the content of the file %s is : \n",fname);
  19398. rewind(fptr1);
  19399. if(ch!=EOF)
  19400. {
  19401. // copy all contents to the temporary file except the specific line
  19402. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19403. {
  19404. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19405. if(str[0]=='\0')
  19406. {
  19407. break;
  19408. }
  19409. //TempStopTransaction格式: 槍號,StopTransaction封包
  19410. strncpy(connectorStr, str, 1);
  19411. if(atoi(connectorStr) != (gun_index+1))
  19412. {
  19413. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19414. fclose(fptr1);
  19415. return ;
  19416. }
  19417. //random_uuid(guid);
  19418. strncpy(guid, str+6, 36); //copy guid
  19419. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19420. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19421. {
  19422. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19423. }
  19424. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19425. OCPP_insert_transaction_msg(NO, str);
  19426. memset(str,0,ARRAY_SIZE(str));
  19427. }
  19428. }
  19429. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19430. fclose(fptr1);
  19431. remove(TempStopTransaction); // remove the original file
  19432. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19433. }
  19434. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19435. {
  19436. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19437. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19438. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19439. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19440. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19441. }
  19442. int GetWebSocketPingInterval(void)
  19443. {
  19444. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19445. }
  19446. int GetServerSign(void)
  19447. {
  19448. return server_sign;
  19449. }
  19450. uint8_t GetOcppSecurityProfile()
  19451. {
  19452. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19453. }
  19454. void GetOcppChargerBoxId(uint8_t *data)
  19455. {
  19456. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19457. }
  19458. void GetOcppSecurityPassword(uint8_t *data)
  19459. {
  19460. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19461. }
  19462. void SetOcppVersion(uint8_t *version)
  19463. {
  19464. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19465. DEBUG_INFO("ocpp version: %s\n", version);
  19466. if(strstr((char*)version, "ocpp1.6") != NULL)
  19467. {
  19468. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19469. }
  19470. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19471. {
  19472. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19473. system("pkill OcppBackend");
  19474. }
  19475. }
  19476. void SetServerSign(int value)
  19477. {
  19478. server_sign = value;
  19479. }
  19480. int GetBootNotificationInterval(void)
  19481. {
  19482. return BootNotificationInterval;
  19483. }
  19484. int GetInternetConn(void)
  19485. {
  19486. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19487. }
  19488. int GetBackendConnectionTimeout(void)
  19489. {
  19490. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19491. }
  19492. int isConnectorInitMode(int gun_index)
  19493. {
  19494. int tempIndex = 0;
  19495. int result = TRUE;
  19496. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19498. {
  19499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19500. {
  19501. tempIndex = ((gun_index==2) ? 1: 0);
  19502. }
  19503. else
  19504. {
  19505. tempIndex = gun_index;
  19506. }
  19507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19508. {
  19509. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19510. {
  19511. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19512. } //end of the same index
  19513. }//end of for CHAdeMO_QUANTITY
  19514. }
  19515. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19516. {
  19517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19518. {
  19519. tempIndex = ((gun_index==2) ? 1: 0);
  19520. }
  19521. else
  19522. {
  19523. tempIndex = gun_index;
  19524. }
  19525. for (int index = 0; index < CCS_QUANTITY; index++)
  19526. {
  19527. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19528. {
  19529. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19530. } //end of the same index
  19531. } // end of for CCS_QUANTITY
  19532. }
  19533. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19534. {
  19535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19536. {
  19537. tempIndex = ((gun_index==2) ? 1: 0);
  19538. }
  19539. else
  19540. {
  19541. tempIndex = gun_index;
  19542. }
  19543. for (int index = 0; index < GB_QUANTITY; index++)
  19544. {
  19545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19546. {
  19547. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19548. } //end of the same index
  19549. } // end of for GB_QUANTITY
  19550. }
  19551. else if(gunType[gun_index] == GUN_TYPE_DO)
  19552. {
  19553. tempIndex = gun_index;
  19554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19555. {
  19556. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19557. {
  19558. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19559. } //end of the same index
  19560. }
  19561. }
  19562. else
  19563. {
  19564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19565. {
  19566. tempIndex = 2;
  19567. }
  19568. else
  19569. {
  19570. tempIndex = gun_index;
  19571. }
  19572. for (int index = 0; index < AC_QUANTITY; index++)
  19573. {
  19574. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19575. {
  19576. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19577. }//end of the same index
  19578. }//end of for AC_QUANTITY
  19579. }
  19580. return result;
  19581. }
  19582. void refreshProcDogTimer()
  19583. {
  19584. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19585. }
  19586. void InitialSystemValue(void)
  19587. {
  19588. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19589. locallistVersion=0;
  19590. BootNotificationInterval = 0;
  19591. authorizeRetryTimes = 0;
  19592. GunStatusInterval = 10;
  19593. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19594. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19595. //Hear Beat
  19596. HeartBeatWithNOResponse = 0;
  19597. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19598. FirstHeartBeat = 0;
  19599. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19600. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19601. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19602. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19603. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19604. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19605. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19606. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19607. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19608. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19609. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19610. //Status && ConnectorPlugIn Setting
  19611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19612. {
  19613. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19614. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19615. }
  19616. for (int index = 0; index < CCS_QUANTITY; index++)
  19617. {
  19618. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19619. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19620. }
  19621. for (int index = 0; index < GB_QUANTITY; index++)
  19622. {
  19623. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19624. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19625. }
  19626. for (int index = 0; index < AC_QUANTITY; index++)
  19627. {
  19628. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19629. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19630. }
  19631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19632. {
  19633. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19634. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19635. }
  19636. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19637. {
  19638. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19639. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19640. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19641. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19642. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19643. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19644. }
  19645. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19646. refreshStartTimer(&clientTime.Heartbeat);
  19647. sleep(1);
  19648. }
  19649. void LWS_Send(char *str)
  19650. {
  19651. //=====================================================
  19652. // Check InternetConn 0: disconnected, 1: connected
  19653. //====================================================
  19654. if(GetOcppConnStatus() == 0)
  19655. {
  19656. DEBUG_INFO("offline now !!!\n");
  19657. return;
  19658. }
  19659. // Only disable isWebsocketSendable operation initiated by charger
  19660. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19661. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19662. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19663. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19664. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19665. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19666. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19667. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19668. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19669. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19670. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19671. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19672. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19673. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19674. {
  19675. isWebsocketSendable = 0;
  19676. }
  19677. pthread_mutex_lock(&lock_send);
  19678. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19679. sprintf((char *)SendBuffer, "%s", str);
  19680. SendBufLen = strlen(str);
  19681. pthread_mutex_unlock(&lock_send);
  19682. lws_callback_on_writable(wsi_client);
  19683. //lws_service(context, 0);
  19684. //sleep(1);
  19685. }
  19686. void LWS_SendNow(char *str)
  19687. {
  19688. //=====================================================
  19689. // Check InternetConn 0: disconnected, 1: connected
  19690. //====================================================
  19691. if(GetOcppConnStatus() == 0)
  19692. {
  19693. DEBUG_INFO("offline now !!!\n");
  19694. return;
  19695. }
  19696. // Only disable isWebsocketSendable operation initiated by charger
  19697. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19698. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19699. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19700. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19701. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19702. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19703. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19704. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19705. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19706. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19707. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19708. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19709. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19710. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19711. {
  19712. isWebsocketSendable = 0;
  19713. }
  19714. pthread_mutex_lock(&lock_send);
  19715. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19716. sprintf((char *)SendBuffer, "%s", str);
  19717. SendBufLen = strlen(str);
  19718. pthread_mutex_unlock(&lock_send);
  19719. lws_callback_on_writable(wsi_client);
  19720. lws_service(context, 0);
  19721. //sleep(1);
  19722. }