MessageHandler.c 960 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016
  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. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //============================================
  79. // OCPP MeterValue request flag
  80. //============================================
  81. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  82. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  83. //=============================================
  84. // OCPP HeartBeat Response Not Receive Counts
  85. //============================================
  86. static int HeartBeatWithNOResponse = 0;
  87. extern sqlite3 *db;
  88. int TransactionMessageAttemptsGet(void);
  89. int TransactionMessageRetryIntervalGet(void);
  90. int GetOcppConnStatus(void);
  91. void SetOcppConnStatus(uint8_t status);
  92. int setKeyValue(char *key, char *value);
  93. void OCPP_get_TableAuthlocalAllData(void);
  94. void processUnkownKey(void);
  95. struct InterLock
  96. {
  97. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1186. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1187. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1188. }
  1189. //==========================================
  1190. // Check time passed since today
  1191. //==========================================
  1192. long long DiffTimebWithNow(struct timeb ST)
  1193. {
  1194. //return milli-second
  1195. struct timeb ET;
  1196. long long StartTime,StopTime;
  1197. ftime(&ET);
  1198. StartTime=(long long)ST.time;
  1199. StopTime=(long long)ET.time;
  1200. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1201. }
  1202. int getTimePassSinceToday(uint8_t gun_index)
  1203. {
  1204. int result = -1;
  1205. static time_t lastTime[4];
  1206. time_t t;
  1207. struct tm *tmStartToday;
  1208. struct timeb tbStartToday;
  1209. t=time(NULL);
  1210. if(difftime(t, lastTime[gun_index])>0)
  1211. {
  1212. tmStartToday=localtime(&t);
  1213. tmStartToday->tm_hour = 0;
  1214. tmStartToday->tm_min = 0;
  1215. tmStartToday->tm_sec = 0;
  1216. tbStartToday.time = mktime(tmStartToday);
  1217. tbStartToday.millitm = 0;
  1218. result = DiffTimebWithNow(tbStartToday)/1000;
  1219. lastTime[gun_index] = t;
  1220. }
  1221. return result;
  1222. }
  1223. void getNowDatetime(uint8_t *data)
  1224. {
  1225. time_t t = time(NULL);
  1226. struct tm tm = *localtime(&t);
  1227. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1228. }
  1229. int syncDateTimeRTC(uint8_t *data)
  1230. {
  1231. struct ParsingResult
  1232. {
  1233. int result;
  1234. int scanedElement;
  1235. int year;
  1236. int month;
  1237. int mday;
  1238. int hour;
  1239. int min;
  1240. int sec;
  1241. int tz_hour;
  1242. int tz_min;
  1243. float minSec;
  1244. }result;
  1245. struct tm tmOrg;
  1246. struct tm *tmTarget;
  1247. struct timeb tbTarget;
  1248. char buf[128];
  1249. memset(&result, 0x00, sizeof(struct ParsingResult));
  1250. result.result = PASS;
  1251. if(strstr((char*)data, ".") != NULL)
  1252. {
  1253. // Original data with mini second
  1254. if(strstr((char*)data, "Z") != NULL)
  1255. {
  1256. // Original data with Z
  1257. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec,
  1264. &result.minSec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.minSec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. // Original data without mini second
  1284. if(strstr((char*)data, "Z") != NULL)
  1285. {
  1286. // Original data with Z
  1287. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1288. &result.year,
  1289. &result.month,
  1290. &result.mday,
  1291. &result.hour,
  1292. &result.min,
  1293. &result.sec);
  1294. }
  1295. else
  1296. {
  1297. // Original data without Z
  1298. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1299. &result.year,
  1300. &result.month,
  1301. &result.mday,
  1302. &result.hour,
  1303. &result.min,
  1304. &result.sec,
  1305. &result.tz_hour,
  1306. &result.tz_min);
  1307. }
  1308. }
  1309. tmOrg.tm_year = result.year - 1900;
  1310. tmOrg.tm_mon = result.month - 1;
  1311. tmOrg.tm_mday = result.mday;
  1312. tmOrg.tm_hour = result.hour;
  1313. tmOrg.tm_min = result.min;
  1314. tmOrg.tm_sec = result.sec;
  1315. tmOrg.tm_gmtoff = 0;
  1316. tbTarget.time = mktime(&tmOrg);
  1317. tbTarget.timezone = 0;
  1318. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1319. tmTarget = gmtime(&tbTarget.time);
  1320. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1321. //DEBUG_INFO(" org date time: %s\n", data);
  1322. //DEBUG_INFO("parse date time: %s\n", buf);
  1323. system(buf);
  1324. system("/sbin/hwclock -w --systohc");
  1325. if(result.scanedElement < 6)
  1326. result.result = FAIL;
  1327. return result.result;
  1328. }
  1329. //==========================================
  1330. // GetCompositeSchedule logic related function
  1331. //==========================================
  1332. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1333. {
  1334. //return milli-second
  1335. unsigned int StartTime,StopTime;
  1336. StartTime=(unsigned int)ST.time;
  1337. StopTime=(unsigned int)ET.time;
  1338. return (StopTime-StartTime);
  1339. }
  1340. int DiffTimebWithNowSec(struct timeb ST)
  1341. {
  1342. //return milli-second
  1343. struct timeb ET;
  1344. unsigned int StartTime,StopTime;
  1345. ftime(&ET);
  1346. StartTime=(unsigned int)ST.time;
  1347. StopTime=(unsigned int)ET.time;
  1348. return (StopTime-StartTime);
  1349. }
  1350. int getStartStop(uint8_t *start, uint8_t *stop)
  1351. {
  1352. struct ParsingResult
  1353. {
  1354. int result;
  1355. int scanedElement;
  1356. int year;
  1357. int month;
  1358. int mday;
  1359. int hour;
  1360. int min;
  1361. int sec;
  1362. int tz_hour;
  1363. int tz_min;
  1364. float minSec;
  1365. };
  1366. struct ParsingResult parseStart;
  1367. struct ParsingResult parseStop;
  1368. int result = -1;
  1369. struct tm tmStart;
  1370. struct timeb tbStart;
  1371. struct tm tmStop;
  1372. struct timeb tbStop;
  1373. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1374. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1375. // Scan start & stop date time
  1376. if(strstr((char*)start, ".") != NULL)
  1377. {
  1378. // Original data with mini second
  1379. if(strstr((char*)start, "Z") != NULL)
  1380. {
  1381. // Original data with Z
  1382. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1383. &parseStart.year,
  1384. &parseStart.month,
  1385. &parseStart.mday,
  1386. &parseStart.hour,
  1387. &parseStart.min,
  1388. &parseStart.sec,
  1389. &parseStart.minSec);
  1390. }
  1391. else
  1392. {
  1393. // Original data without Z
  1394. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1395. &parseStart.year,
  1396. &parseStart.month,
  1397. &parseStart.mday,
  1398. &parseStart.hour,
  1399. &parseStart.min,
  1400. &parseStart.sec,
  1401. &parseStart.minSec,
  1402. &parseStart.tz_hour,
  1403. &parseStart.tz_min);
  1404. }
  1405. }
  1406. else
  1407. {
  1408. // Original data without mini second
  1409. if(strstr((char*)start, "Z") != NULL)
  1410. {
  1411. // Original data with Z
  1412. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1413. &parseStart.year,
  1414. &parseStart.month,
  1415. &parseStart.mday,
  1416. &parseStart.hour,
  1417. &parseStart.min,
  1418. &parseStart.sec);
  1419. }
  1420. else
  1421. {
  1422. // Original data without Z
  1423. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1424. &parseStart.year,
  1425. &parseStart.month,
  1426. &parseStart.mday,
  1427. &parseStart.hour,
  1428. &parseStart.min,
  1429. &parseStart.sec,
  1430. &parseStart.tz_hour,
  1431. &parseStart.tz_min);
  1432. }
  1433. }
  1434. if(strstr((char*)stop, ".") != NULL)
  1435. {
  1436. // Original data with mini second
  1437. if(strstr((char*)stop, "Z") != NULL)
  1438. {
  1439. // Original data with Z
  1440. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1441. &parseStop.year,
  1442. &parseStop.month,
  1443. &parseStop.mday,
  1444. &parseStop.hour,
  1445. &parseStop.min,
  1446. &parseStop.sec,
  1447. &parseStop.minSec);
  1448. }
  1449. else
  1450. {
  1451. // Original data without Z
  1452. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1453. &parseStop.year,
  1454. &parseStop.month,
  1455. &parseStop.mday,
  1456. &parseStop.hour,
  1457. &parseStop.min,
  1458. &parseStop.sec,
  1459. &parseStop.minSec,
  1460. &parseStop.tz_hour,
  1461. &parseStop.tz_min);
  1462. }
  1463. }
  1464. else
  1465. {
  1466. // Original data without mini second
  1467. if(strstr((char*)stop, "Z") != NULL)
  1468. {
  1469. // Original data with Z
  1470. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1471. &parseStop.year,
  1472. &parseStop.month,
  1473. &parseStop.mday,
  1474. &parseStop.hour,
  1475. &parseStop.min,
  1476. &parseStop.sec);
  1477. }
  1478. else
  1479. {
  1480. // Original data without Z
  1481. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1482. &parseStop.year,
  1483. &parseStop.month,
  1484. &parseStop.mday,
  1485. &parseStop.hour,
  1486. &parseStop.min,
  1487. &parseStop.sec,
  1488. &parseStop.tz_hour,
  1489. &parseStop.tz_min);
  1490. }
  1491. }
  1492. // Calculate date time difference
  1493. if((parseStart.scanedElement >=6) &&
  1494. (parseStop.scanedElement >=6))
  1495. {
  1496. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1497. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1498. tmStart.tm_year = parseStart.year - 1900;
  1499. tmStart.tm_mon = parseStart.month - 1;
  1500. tmStart.tm_mday = parseStart.mday;
  1501. tmStart.tm_hour = parseStart.hour;
  1502. tmStart.tm_min = parseStart.min;
  1503. tmStart.tm_sec = parseStart.sec;
  1504. tmStart.tm_gmtoff = 0;
  1505. tbStart.time = mktime(&tmStart);
  1506. tbStart.timezone = 0;
  1507. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1508. tmStop.tm_year = parseStop.year - 1900;
  1509. tmStop.tm_mon = parseStop.month - 1;
  1510. tmStop.tm_mday = parseStop.mday;
  1511. tmStop.tm_hour = parseStop.hour;
  1512. tmStop.tm_min = parseStop.min;
  1513. tmStop.tm_sec = parseStop.sec;
  1514. tmStop.tm_gmtoff = 0;
  1515. tbStop.time = mktime(&tmStop);
  1516. tbStop.timezone = 0;
  1517. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1518. result = DiffTimebSec(tbStart, tbStop);
  1519. //DEBUG_INFO("getStartStop(): %d\n", result);
  1520. }
  1521. else
  1522. {
  1523. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1524. }
  1525. return result;
  1526. }
  1527. int isOvertNow(uint8_t *start)
  1528. {
  1529. int result = NO;
  1530. struct ParsingResult
  1531. {
  1532. int result;
  1533. int scanedElement;
  1534. int year;
  1535. int month;
  1536. int mday;
  1537. int hour;
  1538. int min;
  1539. int sec;
  1540. int tz_hour;
  1541. int tz_min;
  1542. float minSec;
  1543. }parsingResult;
  1544. struct tm tmStart;
  1545. struct timeb tbStart;
  1546. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1547. if(strstr((char*)start, ".") != NULL)
  1548. {
  1549. // Original data with mini second
  1550. if(strstr((char*)start, "Z") != NULL)
  1551. {
  1552. // Original data with Z
  1553. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1554. &parsingResult.year,
  1555. &parsingResult.month,
  1556. &parsingResult.mday,
  1557. &parsingResult.hour,
  1558. &parsingResult.min,
  1559. &parsingResult.sec,
  1560. &parsingResult.minSec);
  1561. }
  1562. else
  1563. {
  1564. // Original data without Z
  1565. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1566. &parsingResult.year,
  1567. &parsingResult.month,
  1568. &parsingResult.mday,
  1569. &parsingResult.hour,
  1570. &parsingResult.min,
  1571. &parsingResult.sec,
  1572. &parsingResult.minSec,
  1573. &parsingResult.tz_hour,
  1574. &parsingResult.tz_min);
  1575. }
  1576. }
  1577. else
  1578. {
  1579. // Original data without mini second
  1580. if(strstr((char*)start, "Z") != NULL)
  1581. {
  1582. // Original data with Z
  1583. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1584. &parsingResult.year,
  1585. &parsingResult.month,
  1586. &parsingResult.mday,
  1587. &parsingResult.hour,
  1588. &parsingResult.min,
  1589. &parsingResult.sec);
  1590. }
  1591. else
  1592. {
  1593. // Original data without Z
  1594. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1595. &parsingResult.year,
  1596. &parsingResult.month,
  1597. &parsingResult.mday,
  1598. &parsingResult.hour,
  1599. &parsingResult.min,
  1600. &parsingResult.sec,
  1601. &parsingResult.tz_hour,
  1602. &parsingResult.tz_min);
  1603. }
  1604. }
  1605. if(parsingResult.scanedElement >= 6)
  1606. {
  1607. tmStart.tm_year = parsingResult.year - 1900;
  1608. tmStart.tm_mon = parsingResult.month - 1;
  1609. tmStart.tm_mday = parsingResult.mday;
  1610. tmStart.tm_hour = parsingResult.hour;
  1611. tmStart.tm_min = parsingResult.min;
  1612. tmStart.tm_sec = parsingResult.sec;
  1613. tmStart.tm_gmtoff = 0;
  1614. tbStart.time = mktime(&tmStart);
  1615. tbStart.timezone = 0;
  1616. tbStart.millitm = 0;
  1617. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1618. if(DiffTimebWithNowSec(tbStart) <= 0)
  1619. result = NO;
  1620. else
  1621. result = YES;
  1622. }
  1623. else
  1624. {
  1625. DEBUG_WARN("Start date parsing error.\n");
  1626. }
  1627. return result;
  1628. }
  1629. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1630. {
  1631. struct ParsingResult
  1632. {
  1633. int result;
  1634. int scanedElement;
  1635. int year;
  1636. int month;
  1637. int mday;
  1638. int hour;
  1639. int min;
  1640. int sec;
  1641. int tz_hour;
  1642. int tz_min;
  1643. float minSec;
  1644. };
  1645. struct ParsingResult parseStart;
  1646. struct ParsingResult parseStop;
  1647. int result = -1;
  1648. struct tm tmStart;
  1649. struct timeb tbStart;
  1650. struct tm tmStop;
  1651. struct timeb tbStop;
  1652. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1653. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1654. // Scan start & stop date time
  1655. if(strstr((char*)start, ".") != NULL)
  1656. {
  1657. // Original data with mini second
  1658. if(strstr((char*)start, "Z") != NULL)
  1659. {
  1660. // Original data with Z
  1661. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1662. &parseStart.year,
  1663. &parseStart.month,
  1664. &parseStart.mday,
  1665. &parseStart.hour,
  1666. &parseStart.min,
  1667. &parseStart.sec,
  1668. &parseStart.minSec);
  1669. }
  1670. else
  1671. {
  1672. // Original data without Z
  1673. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1674. &parseStart.year,
  1675. &parseStart.month,
  1676. &parseStart.mday,
  1677. &parseStart.hour,
  1678. &parseStart.min,
  1679. &parseStart.sec,
  1680. &parseStart.minSec,
  1681. &parseStart.tz_hour,
  1682. &parseStart.tz_min);
  1683. }
  1684. }
  1685. else
  1686. {
  1687. // Original data without mini second
  1688. if(strstr((char*)start, "Z") != NULL)
  1689. {
  1690. // Original data with Z
  1691. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1692. &parseStart.year,
  1693. &parseStart.month,
  1694. &parseStart.mday,
  1695. &parseStart.hour,
  1696. &parseStart.min,
  1697. &parseStart.sec);
  1698. }
  1699. else
  1700. {
  1701. // Original data without Z
  1702. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1703. &parseStart.year,
  1704. &parseStart.month,
  1705. &parseStart.mday,
  1706. &parseStart.hour,
  1707. &parseStart.min,
  1708. &parseStart.sec,
  1709. &parseStart.tz_hour,
  1710. &parseStart.tz_min);
  1711. }
  1712. }
  1713. if(strstr((char*)stop, ".") != NULL)
  1714. {
  1715. // Original data with mini second
  1716. if(strstr((char*)stop, "Z") != NULL)
  1717. {
  1718. // Original data with Z
  1719. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1720. &parseStop.year,
  1721. &parseStop.month,
  1722. &parseStop.mday,
  1723. &parseStop.hour,
  1724. &parseStop.min,
  1725. &parseStop.sec,
  1726. &parseStop.minSec);
  1727. }
  1728. else
  1729. {
  1730. // Original data without Z
  1731. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1732. &parseStop.year,
  1733. &parseStop.month,
  1734. &parseStop.mday,
  1735. &parseStop.hour,
  1736. &parseStop.min,
  1737. &parseStop.sec,
  1738. &parseStop.minSec,
  1739. &parseStop.tz_hour,
  1740. &parseStop.tz_min);
  1741. }
  1742. }
  1743. else
  1744. {
  1745. // Original data without mini second
  1746. if(strstr((char*)stop, "Z") != NULL)
  1747. {
  1748. // Original data with Z
  1749. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1750. &parseStop.year,
  1751. &parseStop.month,
  1752. &parseStop.mday,
  1753. &parseStop.hour,
  1754. &parseStop.min,
  1755. &parseStop.sec);
  1756. }
  1757. else
  1758. {
  1759. // Original data without Z
  1760. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1761. &parseStop.year,
  1762. &parseStop.month,
  1763. &parseStop.mday,
  1764. &parseStop.hour,
  1765. &parseStop.min,
  1766. &parseStop.sec,
  1767. &parseStop.tz_hour,
  1768. &parseStop.tz_min);
  1769. }
  1770. }
  1771. // Calculate date time difference
  1772. if((parseStart.scanedElement >=6) &&
  1773. (parseStop.scanedElement >=6))
  1774. {
  1775. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1776. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1777. tmStart.tm_year = parseStart.year - 1900;
  1778. tmStart.tm_mon = parseStart.month - 1;
  1779. tmStart.tm_mday = parseStart.mday;
  1780. tmStart.tm_hour = parseStart.hour;
  1781. tmStart.tm_min = parseStart.min;
  1782. tmStart.tm_sec = parseStart.sec;
  1783. tmStart.tm_gmtoff = 0;
  1784. tbStart.time = mktime(&tmStart);
  1785. tbStart.timezone = 0;
  1786. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1787. tmStop.tm_year = parseStop.year - 1900;
  1788. tmStop.tm_mon = parseStop.month - 1;
  1789. tmStop.tm_mday = parseStop.mday;
  1790. tmStop.tm_hour = parseStop.hour;
  1791. tmStop.tm_min = parseStop.min;
  1792. tmStop.tm_sec = parseStop.sec;
  1793. tmStop.tm_gmtoff = 0;
  1794. tbStop.time = mktime(&tmStop);
  1795. tbStop.timezone = 0;
  1796. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1797. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1798. //DEBUG_INFO("getStartStop(): %d\n", result);
  1799. }
  1800. else
  1801. {
  1802. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1803. }
  1804. return result;
  1805. }
  1806. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1807. {
  1808. FILE *fp;
  1809. char profileFileName[128];
  1810. char *line = NULL;
  1811. size_t len = 0;
  1812. time_t CurrentTime;
  1813. struct tm *tmComposite;
  1814. struct StructChargingProfile maxProfile;
  1815. struct StructChargingProfile compositeProfile;
  1816. uint8_t limitMax=0;
  1817. int compositePeriodIdx = 0;
  1818. CurrentTime = time(NULL);
  1819. tmComposite=localtime(&CurrentTime);
  1820. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1821. if(isUnitA)
  1822. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. else
  1824. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1825. compositeProfile.ChargingSchedule.Duration = durationReq;
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1829. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1830. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1831. }
  1832. compositeProfile.ChargingProfileId = 0;
  1833. compositeProfile.StackLevel = 99 ;
  1834. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1835. maxProfile.ChargingProfileId = -1;
  1836. maxProfile.ChargingSchedule.Duration = -1;
  1837. system("rm -f /tmp/*.json");
  1838. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1839. // Search max profile
  1840. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1841. if((access(profileFileName, F_OK))!=-1)
  1842. {
  1843. fp = fopen(profileFileName, "r");
  1844. while(getline(&line, &len, fp) != -1)
  1845. {
  1846. json_object *obj = NULL;
  1847. obj = json_tokener_parse(line);
  1848. if(is_error(obj))
  1849. {
  1850. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1851. }
  1852. else
  1853. {
  1854. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1855. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1856. )
  1857. {
  1858. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1859. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1860. )
  1861. {
  1862. struct tm tmFrom, tmTo;
  1863. struct timeb tbFrom, tbTo;
  1864. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1865. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1866. {
  1867. tmFrom.tm_year -= 1900;
  1868. tmFrom.tm_mon -= 1;
  1869. tbFrom.time = mktime(&tmFrom);
  1870. tmTo.tm_year -= 1900;
  1871. tmTo.tm_mon -= 1;
  1872. tbTo.time = mktime(&tmTo);
  1873. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1874. {
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1880. }
  1881. if(maxProfile.ChargingProfileId == -1)
  1882. DEBUG_INFO("MaxProfile found.\n");
  1883. else
  1884. DEBUG_INFO("MaxProfile updated.\n");
  1885. // Required item
  1886. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1887. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1888. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1889. if(isUnitA)
  1890. {
  1891. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1892. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1893. {
  1894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1895. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1896. 3:
  1897. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1898. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1899. }
  1900. }
  1901. else
  1902. {
  1903. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1904. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1905. {
  1906. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1907. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1908. 3:
  1909. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1911. }
  1912. }
  1913. // Optional item
  1914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1915. {
  1916. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1917. }
  1918. else
  1919. {
  1920. sprintf((char*)maxProfile.ValidFrom, " ");
  1921. }
  1922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1923. {
  1924. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1925. }
  1926. else
  1927. {
  1928. sprintf((char*)maxProfile.ValidTo, " ");
  1929. }
  1930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1931. {
  1932. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1937. }
  1938. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1939. {
  1940. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1941. }
  1942. else
  1943. {
  1944. maxProfile.TransactionId = -1;
  1945. }
  1946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1947. {
  1948. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1949. }
  1950. else
  1951. {
  1952. maxProfile.ChargingSchedule.Duration = 86400;
  1953. }
  1954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1955. {
  1956. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1961. }
  1962. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1963. {
  1964. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1965. }
  1966. else
  1967. {
  1968. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1969. }
  1970. }
  1971. }
  1972. }
  1973. else
  1974. {
  1975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1976. {
  1977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1980. }
  1981. if(maxProfile.ChargingProfileId == -1)
  1982. DEBUG_INFO("MaxProfile found.\n");
  1983. else
  1984. DEBUG_INFO("MaxProfile updated.\n");
  1985. // Required item
  1986. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1987. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1988. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1989. if(isUnitA)
  1990. {
  1991. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1992. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1993. {
  1994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1995. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1996. 3:
  1997. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1999. }
  2000. }
  2001. else
  2002. {
  2003. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2004. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2005. {
  2006. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2007. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2008. 3:
  2009. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2010. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2011. }
  2012. }
  2013. // Optional item
  2014. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2015. {
  2016. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2017. }
  2018. else
  2019. {
  2020. sprintf((char*)maxProfile.ValidFrom, " ");
  2021. }
  2022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2023. {
  2024. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2025. }
  2026. else
  2027. {
  2028. sprintf((char*)maxProfile.ValidTo, " ");
  2029. }
  2030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2031. {
  2032. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2037. }
  2038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2039. {
  2040. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2041. }
  2042. else
  2043. {
  2044. maxProfile.TransactionId = -1;
  2045. }
  2046. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2047. {
  2048. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2049. }
  2050. else
  2051. {
  2052. maxProfile.ChargingSchedule.Duration = 86400;
  2053. }
  2054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2055. {
  2056. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2057. }
  2058. else
  2059. {
  2060. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2063. {
  2064. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2065. }
  2066. else
  2067. {
  2068. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2069. }
  2070. }
  2071. }
  2072. }
  2073. json_object_put(obj);
  2074. }
  2075. fclose(fp);
  2076. /*
  2077. if(maxProfile.ChargingProfileId !=-1)
  2078. {
  2079. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2080. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2081. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2082. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2083. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2084. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2085. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2086. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2087. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2088. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2089. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2090. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2091. {
  2092. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2093. {
  2094. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2095. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2096. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. DEBUG_INFO("MaxProfile not found.\n");
  2102. DEBUG_INFO("------------------------------------\n");*/
  2103. }
  2104. if(maxProfile.ChargingProfileId != -1)
  2105. {
  2106. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2107. {
  2108. if(maxProfile.ChargingSchedule.Duration != -1)
  2109. {
  2110. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2111. 0:
  2112. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2113. }
  2114. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2115. {
  2116. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2117. {
  2118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. if(idxPeriod > 0)
  2122. {
  2123. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2124. {
  2125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2132. {
  2133. if(maxProfile.ChargingSchedule.Duration != -1)
  2134. {
  2135. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2136. }
  2137. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2138. {
  2139. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2140. {
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2142. if(idxPeriod > 0)
  2143. {
  2144. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2145. {
  2146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. else
  2153. {
  2154. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2155. {
  2156. if(maxProfile.ChargingSchedule.Duration != -1)
  2157. {
  2158. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2159. 0:
  2160. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2161. }
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. if(idxPeriod > 0)
  2170. {
  2171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. else
  2180. {
  2181. if(maxProfile.ChargingSchedule.Duration != -1)
  2182. {
  2183. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2184. 0:
  2185. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2186. }
  2187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2188. {
  2189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. if(idxPeriod > 0)
  2195. {
  2196. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2197. {
  2198. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. /*
  2206. DEBUG_INFO("MaxProfile after align.\n");
  2207. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2208. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2209. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2210. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2211. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2212. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2213. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2214. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2215. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2216. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2217. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2219. {
  2220. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2221. {
  2222. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2223. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2224. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2225. }
  2226. }
  2227. DEBUG_INFO("------------------------------------\n");*/
  2228. }
  2229. // Find each profile period quantity
  2230. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2231. {
  2232. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2233. limitMax = idx+1;
  2234. }
  2235. if(maxProfile.ChargingProfileId != -1)
  2236. {
  2237. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2238. {
  2239. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2240. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2241. (maxProfile.ChargingSchedule.Duration > 0))
  2242. {
  2243. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2244. {
  2245. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2246. compositePeriodIdx++;
  2247. }
  2248. else
  2249. {
  2250. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2251. }
  2252. }
  2253. }
  2254. }
  2255. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2256. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2257. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2258. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2260. {
  2261. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2262. {
  2263. compositeProfile.ChargingProfileId = 1;
  2264. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2265. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2266. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2267. }
  2268. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2269. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2270. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2271. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2272. }
  2273. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2274. if(line)
  2275. free(line);
  2276. }
  2277. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2278. {
  2279. FILE *fp;
  2280. char profileFileName[128];
  2281. char *line = NULL;
  2282. size_t len = 0;
  2283. time_t CurrentTime;
  2284. struct tm *tmComposite;
  2285. struct StructChargingProfile maxProfile;
  2286. struct StructChargingProfile defaultTxProfile;
  2287. struct StructChargingProfile txProfile;
  2288. struct StructChargingProfile compositeProfile;
  2289. struct StructChargingSchedulePeriod tmpPeriod;
  2290. uint8_t limitMax=0;
  2291. uint8_t limitDef=0;
  2292. uint8_t limitTx=0;
  2293. int compositePeriodIdx = 0;
  2294. CurrentTime = time(NULL);
  2295. tmComposite=localtime(&CurrentTime);
  2296. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2297. if(isUnitA)
  2298. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2299. else
  2300. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2301. compositeProfile.ChargingSchedule.Duration = durationReq;
  2302. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2303. {
  2304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2306. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2307. }
  2308. compositeProfile.ChargingProfileId = 0;
  2309. compositeProfile.StackLevel = 99 ;
  2310. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2311. maxProfile.ChargingProfileId = -1;
  2312. defaultTxProfile.ChargingProfileId = -1;
  2313. txProfile.ChargingProfileId = -1;
  2314. maxProfile.ChargingSchedule.Duration = -1;
  2315. defaultTxProfile.ChargingSchedule.Duration = -1;
  2316. txProfile.ChargingSchedule.Duration = -1;
  2317. system("rm -f /tmp/*.json");
  2318. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2319. /*
  2320. * Search valid charging profile
  2321. */
  2322. //DEBUG_INFO("====================================\n");
  2323. // Search tx profile
  2324. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2325. if((access(profileFileName, F_OK))!=-1)
  2326. {
  2327. fp = fopen(profileFileName, "r");
  2328. while(getline(&line, &len, fp) != -1)
  2329. {
  2330. json_object *obj = NULL;
  2331. obj = json_tokener_parse(line);
  2332. if(is_error(obj))
  2333. {
  2334. DEBUG_ERROR("Parse txProfile from file error.\n");
  2335. }
  2336. else
  2337. {
  2338. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2339. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2340. )
  2341. {
  2342. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2343. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2344. )
  2345. {
  2346. struct tm tmFrom, tmTo;
  2347. struct timeb tbFrom, tbTo;
  2348. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2349. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2350. {
  2351. tmFrom.tm_year -= 1900;
  2352. tmFrom.tm_mon -= 1;
  2353. tbFrom.time = mktime(&tmFrom);
  2354. tmTo.tm_year -= 1900;
  2355. tmTo.tm_mon -= 1;
  2356. tbTo.time = mktime(&tmTo);
  2357. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2358. {
  2359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2360. {
  2361. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2364. }
  2365. if(txProfile.ChargingProfileId == -1)
  2366. DEBUG_INFO("TxProfile found.\n");
  2367. else
  2368. DEBUG_INFO("TxProfile updated.\n");
  2369. // Required item
  2370. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2371. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2372. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2373. if(isUnitA)
  2374. {
  2375. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2376. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2377. {
  2378. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2379. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2380. 3:
  2381. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2383. }
  2384. }
  2385. else
  2386. {
  2387. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2388. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2389. {
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2391. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2392. 3:
  2393. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2394. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2395. }
  2396. }
  2397. // Optional item
  2398. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2399. {
  2400. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2401. }
  2402. else
  2403. {
  2404. sprintf((char*)txProfile.ValidFrom, " ");
  2405. }
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidTo, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.RecurrencyKind, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2423. {
  2424. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2425. }
  2426. else
  2427. {
  2428. txProfile.TransactionId = -1;
  2429. }
  2430. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2431. {
  2432. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.ChargingSchedule.Duration = 86400;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2439. {
  2440. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2441. }
  2442. else
  2443. {
  2444. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2447. {
  2448. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2449. }
  2450. else
  2451. {
  2452. txProfile.ChargingSchedule.MinChargingRate = -1;
  2453. }
  2454. }
  2455. }
  2456. }
  2457. else
  2458. {
  2459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2460. {
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2462. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2464. }
  2465. if(txProfile.ChargingProfileId == -1)
  2466. DEBUG_INFO("TxProfile found.\n");
  2467. else
  2468. DEBUG_INFO("TxProfile updated.\n");
  2469. // Required item
  2470. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2471. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2472. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2473. if(isUnitA)
  2474. {
  2475. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2476. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2477. {
  2478. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2479. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2480. 3:
  2481. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2482. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2483. }
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2488. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2489. {
  2490. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2491. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2492. 3:
  2493. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2494. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2495. }
  2496. }
  2497. // Optional item
  2498. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2499. {
  2500. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2501. }
  2502. else
  2503. {
  2504. sprintf((char*)txProfile.ValidFrom, " ");
  2505. }
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidTo, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.RecurrencyKind, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2523. {
  2524. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2525. }
  2526. else
  2527. {
  2528. txProfile.TransactionId = -1;
  2529. }
  2530. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2531. {
  2532. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.ChargingSchedule.Duration = 86400;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2539. {
  2540. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2541. }
  2542. else
  2543. {
  2544. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2547. {
  2548. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2549. }
  2550. else
  2551. {
  2552. txProfile.ChargingSchedule.MinChargingRate = -1;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. json_object_put(obj);
  2558. }
  2559. fclose(fp);
  2560. /*
  2561. if(txProfile.ChargingProfileId != -1)
  2562. {
  2563. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2564. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2565. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2566. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2567. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2568. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2569. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2570. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2571. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2572. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2573. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2575. {
  2576. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2577. {
  2578. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2579. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2580. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2581. }
  2582. }
  2583. }
  2584. else
  2585. DEBUG_INFO("TxProfile not found.\n");*/
  2586. }
  2587. // Search default tx profile
  2588. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2589. if((access(profileFileName, F_OK))==-1)
  2590. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2591. if((access(profileFileName, F_OK))!=-1)
  2592. {
  2593. fp = fopen(profileFileName, "r");
  2594. while(getline(&line, &len, fp) != -1)
  2595. {
  2596. json_object *obj = NULL;
  2597. obj = json_tokener_parse(line);
  2598. if(is_error(obj))
  2599. {
  2600. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2601. }
  2602. else
  2603. {
  2604. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2605. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2606. )
  2607. {
  2608. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2609. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. )
  2611. {
  2612. struct tm tmFrom, tmTo;
  2613. struct timeb tbFrom, tbTo;
  2614. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2615. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2616. {
  2617. tmFrom.tm_year -= 1900;
  2618. tmFrom.tm_mon -= 1;
  2619. tbFrom.time = mktime(&tmFrom);
  2620. tmTo.tm_year -= 1900;
  2621. tmTo.tm_mon -= 1;
  2622. tbTo.time = mktime(&tmTo);
  2623. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2624. {
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2628. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2629. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2630. }
  2631. if(defaultTxProfile.ChargingProfileId == -1)
  2632. DEBUG_INFO("TxDefaultProfile found.\n");
  2633. else
  2634. DEBUG_INFO("TxDefaultProfile updated.\n");
  2635. // Required item
  2636. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2637. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2638. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2639. if(isUnitA)
  2640. {
  2641. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2642. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2643. {
  2644. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2645. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2646. 3:
  2647. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2648. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2654. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2655. {
  2656. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2657. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2658. 3:
  2659. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2660. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2661. }
  2662. }
  2663. // Optional item
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2665. {
  2666. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2667. }
  2668. else
  2669. {
  2670. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2671. }
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2689. {
  2690. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2691. }
  2692. else
  2693. {
  2694. defaultTxProfile.TransactionId = -1;
  2695. }
  2696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2697. {
  2698. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2705. {
  2706. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2707. }
  2708. else
  2709. {
  2710. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2715. }
  2716. else
  2717. {
  2718. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. else
  2724. {
  2725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2726. {
  2727. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2729. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2730. }
  2731. if(defaultTxProfile.ChargingProfileId == -1)
  2732. DEBUG_INFO("TxDefaultProfile found.\n");
  2733. else
  2734. DEBUG_INFO("TxDefaultProfile updated.\n");
  2735. // Required item
  2736. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2737. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2738. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2739. if(isUnitA)
  2740. {
  2741. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2742. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2743. {
  2744. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2745. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2746. 3:
  2747. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2749. }
  2750. }
  2751. else
  2752. {
  2753. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2754. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2755. {
  2756. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2757. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2758. 3:
  2759. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2760. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2761. }
  2762. }
  2763. // Optional item
  2764. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2765. {
  2766. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2767. }
  2768. else
  2769. {
  2770. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2771. }
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2789. {
  2790. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2791. }
  2792. else
  2793. {
  2794. defaultTxProfile.TransactionId = -1;
  2795. }
  2796. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2797. {
  2798. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2805. {
  2806. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2807. }
  2808. else
  2809. {
  2810. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2815. }
  2816. else
  2817. {
  2818. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2819. }
  2820. }
  2821. }
  2822. }
  2823. json_object_put(obj);
  2824. }
  2825. fclose(fp);
  2826. /*
  2827. if(defaultTxProfile.ChargingProfileId != -1)
  2828. {
  2829. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2830. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2831. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2832. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2833. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2834. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2835. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2836. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2837. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2838. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2839. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2841. {
  2842. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2843. {
  2844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2847. }
  2848. }
  2849. }
  2850. else
  2851. DEBUG_INFO("TxDefaultProfile not found.\n");
  2852. DEBUG_INFO("------------------------------------\n");*/
  2853. }
  2854. // Search max profile
  2855. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2856. if((access(profileFileName, F_OK))!=-1)
  2857. {
  2858. fp = fopen(profileFileName, "r");
  2859. while(getline(&line, &len, fp) != -1)
  2860. {
  2861. json_object *obj = NULL;
  2862. obj = json_tokener_parse(line);
  2863. if(is_error(obj))
  2864. {
  2865. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2866. }
  2867. else
  2868. {
  2869. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2870. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2871. )
  2872. {
  2873. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2874. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2875. )
  2876. {
  2877. struct tm tmFrom, tmTo;
  2878. struct timeb tbFrom, tbTo;
  2879. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2880. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2881. {
  2882. tmFrom.tm_year -= 1900;
  2883. tmFrom.tm_mon -= 1;
  2884. tbFrom.time = mktime(&tmFrom);
  2885. tmTo.tm_year -= 1900;
  2886. tmTo.tm_mon -= 1;
  2887. tbTo.time = mktime(&tmTo);
  2888. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2889. {
  2890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2893. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2895. }
  2896. if(maxProfile.ChargingProfileId == -1)
  2897. DEBUG_INFO("MaxProfile found.\n");
  2898. else
  2899. DEBUG_INFO("MaxProfile updated.\n");
  2900. // Required item
  2901. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2902. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2903. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2904. if(isUnitA)
  2905. {
  2906. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2907. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2908. {
  2909. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2911. 3:
  2912. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2913. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2914. }
  2915. }
  2916. else
  2917. {
  2918. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2919. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2920. {
  2921. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2922. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2923. 3:
  2924. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2925. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2926. }
  2927. }
  2928. // Optional item
  2929. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2930. {
  2931. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2932. }
  2933. else
  2934. {
  2935. sprintf((char*)maxProfile.ValidFrom, " ");
  2936. }
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidTo, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2954. {
  2955. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2956. }
  2957. else
  2958. {
  2959. maxProfile.TransactionId = -1;
  2960. }
  2961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2962. {
  2963. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.ChargingSchedule.Duration = 86400;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2970. {
  2971. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2972. }
  2973. else
  2974. {
  2975. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2978. {
  2979. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2980. }
  2981. else
  2982. {
  2983. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2984. }
  2985. }
  2986. }
  2987. }
  2988. else
  2989. {
  2990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2991. {
  2992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2995. }
  2996. if(maxProfile.ChargingProfileId == -1)
  2997. DEBUG_INFO("MaxProfile found.\n");
  2998. else
  2999. DEBUG_INFO("MaxProfile updated.\n");
  3000. // Required item
  3001. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3002. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3003. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3004. if(isUnitA)
  3005. {
  3006. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3007. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3008. {
  3009. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3010. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3011. 3:
  3012. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3013. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3014. }
  3015. }
  3016. else
  3017. {
  3018. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3019. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3020. {
  3021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3022. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3023. 3:
  3024. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3025. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3026. }
  3027. }
  3028. // Optional item
  3029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3030. {
  3031. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3032. }
  3033. else
  3034. {
  3035. sprintf((char*)maxProfile.ValidFrom, " ");
  3036. }
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidTo, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3054. {
  3055. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3056. }
  3057. else
  3058. {
  3059. maxProfile.TransactionId = -1;
  3060. }
  3061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3062. {
  3063. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.ChargingSchedule.Duration = 86400;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3070. {
  3071. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3072. }
  3073. else
  3074. {
  3075. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3078. {
  3079. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3080. }
  3081. else
  3082. {
  3083. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3084. }
  3085. }
  3086. }
  3087. }
  3088. json_object_put(obj);
  3089. }
  3090. fclose(fp);
  3091. /*
  3092. if(maxProfile.ChargingProfileId !=-1)
  3093. {
  3094. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3095. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3096. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3097. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3098. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3099. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3100. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3101. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3102. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3103. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3104. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3105. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3106. {
  3107. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3108. {
  3109. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3110. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3111. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3112. }
  3113. }
  3114. }
  3115. else
  3116. DEBUG_INFO("MaxProfile not found.\n");
  3117. DEBUG_INFO("------------------------------------\n");*/
  3118. }
  3119. /*
  3120. * Align found profile start schedule & periods
  3121. */
  3122. //DEBUG_INFO("====================================\n");
  3123. /*
  3124. // For local test usage, force modify found profile start schedule info
  3125. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  3126. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  3127. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  3128. */
  3129. if(txProfile.ChargingProfileId != -1)
  3130. {
  3131. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3132. {
  3133. if(txProfile.ChargingSchedule.Duration != -1)
  3134. {
  3135. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3136. 0:
  3137. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3138. }
  3139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3140. {
  3141. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3142. {
  3143. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. if(idxPeriod > 0)
  3147. {
  3148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3149. {
  3150. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3157. {
  3158. if(txProfile.ChargingSchedule.Duration != -1)
  3159. {
  3160. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3161. 0:
  3162. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3163. }
  3164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3165. {
  3166. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3167. {
  3168. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3169. 0:
  3170. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. if(idxPeriod > 0)
  3172. {
  3173. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3174. {
  3175. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3176. }
  3177. }
  3178. }
  3179. }
  3180. }
  3181. else
  3182. {
  3183. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3184. {
  3185. if(txProfile.ChargingSchedule.Duration != -1)
  3186. {
  3187. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3188. 0:
  3189. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3190. }
  3191. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3192. {
  3193. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3194. {
  3195. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. if(idxPeriod > 0)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3201. {
  3202. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3203. }
  3204. }
  3205. }
  3206. }
  3207. }
  3208. else
  3209. {
  3210. if(txProfile.ChargingSchedule.Duration != -1)
  3211. {
  3212. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3213. 0:
  3214. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3215. }
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3219. {
  3220. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. if(idxPeriod > 0)
  3224. {
  3225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3226. {
  3227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. /*
  3235. DEBUG_INFO("txProfile after align.\n");
  3236. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3237. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3238. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3239. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3240. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3242. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3243. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3244. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3245. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3246. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3248. {
  3249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3250. {
  3251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3254. }
  3255. }*/
  3256. }
  3257. if(defaultTxProfile.ChargingProfileId != -1)
  3258. {
  3259. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3260. {
  3261. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3262. {
  3263. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3264. 0:
  3265. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3266. }
  3267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. if(idxPeriod > 0)
  3275. {
  3276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3277. {
  3278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3279. }
  3280. }
  3281. }
  3282. }
  3283. }
  3284. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3285. {
  3286. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3287. {
  3288. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3289. 0:
  3290. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3291. }
  3292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3295. {
  3296. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. if(idxPeriod > 0)
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3302. {
  3303. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3312. {
  3313. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3314. {
  3315. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3316. 0:
  3317. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3318. }
  3319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. if(idxPeriod > 0)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3329. {
  3330. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3331. }
  3332. }
  3333. }
  3334. }
  3335. }
  3336. else
  3337. {
  3338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3339. {
  3340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3341. 0:
  3342. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3343. }
  3344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. if(idxPeriod > 0)
  3352. {
  3353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3354. {
  3355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. }
  3362. /*
  3363. DEBUG_INFO("defaultTxProfile after align.\n");
  3364. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3365. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3366. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3367. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3368. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3369. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3370. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3371. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3372. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3373. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3374. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3378. {
  3379. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3380. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3381. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3382. }
  3383. }
  3384. DEBUG_INFO("------------------------------------\n");*/
  3385. }
  3386. if(maxProfile.ChargingProfileId != -1)
  3387. {
  3388. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3389. {
  3390. if(maxProfile.ChargingSchedule.Duration != -1)
  3391. {
  3392. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3393. 0:
  3394. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3395. }
  3396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3397. {
  3398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. if(idxPeriod > 0)
  3404. {
  3405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3406. {
  3407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3414. {
  3415. if(maxProfile.ChargingSchedule.Duration != -1)
  3416. {
  3417. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3418. 0:
  3419. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3420. }
  3421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3422. {
  3423. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3424. {
  3425. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. if(idxPeriod > 0)
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3431. {
  3432. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3433. }
  3434. }
  3435. }
  3436. }
  3437. }
  3438. else
  3439. {
  3440. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3441. {
  3442. if(maxProfile.ChargingSchedule.Duration != -1)
  3443. {
  3444. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3445. 0:
  3446. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3447. }
  3448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3449. {
  3450. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. if(idxPeriod > 0)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3458. {
  3459. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. }
  3465. else
  3466. {
  3467. if(maxProfile.ChargingSchedule.Duration != -1)
  3468. {
  3469. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3470. 0:
  3471. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3472. }
  3473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3474. {
  3475. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. if(idxPeriod > 0)
  3481. {
  3482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3483. {
  3484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. }
  3491. /*
  3492. DEBUG_INFO("MaxProfile after align.\n");
  3493. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3494. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3495. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3496. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3497. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3498. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3499. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3500. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3501. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3502. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3503. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3505. {
  3506. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3507. {
  3508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3511. }
  3512. }
  3513. DEBUG_INFO("------------------------------------\n");*/
  3514. }
  3515. /*
  3516. * Merge to conposite schedule
  3517. */
  3518. //DEBUG_INFO("====================================\n");
  3519. // Find each profile period quantity
  3520. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3521. {
  3522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3523. limitMax = idx+1;
  3524. }
  3525. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3526. {
  3527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3528. limitDef = idx+1;
  3529. }
  3530. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3533. limitTx = idx+1;
  3534. }
  3535. // TxProfile found, composite schedule based on it
  3536. if(txProfile.ChargingProfileId != -1)
  3537. {
  3538. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3539. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3540. {
  3541. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3542. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3543. (txProfile.ChargingSchedule.Duration > 0))
  3544. {
  3545. if(maxProfile.ChargingProfileId != -1)
  3546. {
  3547. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3550. {
  3551. if((maxProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3554. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3555. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3556. }
  3557. else
  3558. {
  3559. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3560. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3561. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3562. }
  3563. }
  3564. if(idxMaxPeriod == (limitMax-1))
  3565. {
  3566. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3567. {
  3568. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3569. {
  3570. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3571. compositePeriodIdx++;
  3572. }
  3573. else
  3574. {
  3575. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }
  3581. else
  3582. {
  3583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3584. {
  3585. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3586. compositePeriodIdx++;
  3587. }
  3588. else
  3589. {
  3590. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3591. }
  3592. }
  3593. }
  3594. if(idxTxPeriod == (limitTx-1))
  3595. {
  3596. if(defaultTxProfile.ChargingProfileId != -1)
  3597. {
  3598. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3599. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3600. {
  3601. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3602. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3603. (defaultTxProfile.ChargingSchedule.Duration>0))
  3604. {
  3605. if(maxProfile.ChargingProfileId != -1)
  3606. {
  3607. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3608. {
  3609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3610. {
  3611. if((maxProfile.ChargingSchedule.Duration > 0))
  3612. {
  3613. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3614. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3615. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3616. }
  3617. else
  3618. {
  3619. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3620. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3621. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3622. }
  3623. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3624. {
  3625. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3626. {
  3627. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3628. compositePeriodIdx++;
  3629. }
  3630. else
  3631. {
  3632. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3633. }
  3634. }
  3635. // Delete duplicate period
  3636. if(compositePeriodIdx > 1)
  3637. {
  3638. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3639. {
  3640. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3641. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3642. compositePeriodIdx -= 1;
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3649. {
  3650. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3651. compositePeriodIdx++;
  3652. }
  3653. else
  3654. {
  3655. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3656. }
  3657. break;
  3658. }
  3659. }
  3660. }
  3661. else
  3662. {
  3663. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3664. {
  3665. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3666. compositePeriodIdx++;
  3667. }
  3668. else
  3669. {
  3670. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3671. }
  3672. }
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3680. else if(defaultTxProfile.ChargingProfileId != -1)
  3681. {
  3682. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3683. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3684. {
  3685. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3686. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3687. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3688. {
  3689. if(maxProfile.ChargingProfileId != -1)
  3690. {
  3691. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3692. {
  3693. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3694. {
  3695. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3696. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3697. if((maxProfile.ChargingSchedule.Duration > 0))
  3698. {
  3699. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3700. }
  3701. else
  3702. {
  3703. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3704. }
  3705. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3706. {
  3707. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3708. {
  3709. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3710. compositePeriodIdx++;
  3711. }
  3712. else
  3713. {
  3714. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3715. }
  3716. }
  3717. // Delete duplicate period
  3718. if(compositePeriodIdx > 1)
  3719. {
  3720. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3721. {
  3722. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3723. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3724. compositePeriodIdx -= 1;
  3725. }
  3726. }
  3727. }
  3728. else
  3729. {
  3730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3731. {
  3732. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3733. compositePeriodIdx++;
  3734. }
  3735. else
  3736. {
  3737. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3738. }
  3739. break;
  3740. }
  3741. }
  3742. }
  3743. else
  3744. {
  3745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3746. {
  3747. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3748. compositePeriodIdx++;
  3749. }
  3750. else
  3751. {
  3752. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3753. }
  3754. }
  3755. }
  3756. }
  3757. }
  3758. // Fill other period by MaxProfile
  3759. if(maxProfile.ChargingProfileId != -1)
  3760. {
  3761. if(compositePeriodIdx==0)
  3762. {
  3763. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3764. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3765. {
  3766. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3767. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3768. (maxProfile.ChargingSchedule.Duration > 0))
  3769. {
  3770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3771. {
  3772. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3773. compositePeriodIdx++;
  3774. }
  3775. else
  3776. {
  3777. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3778. }
  3779. }
  3780. }
  3781. }
  3782. else
  3783. {
  3784. int lastCompositePeriodIdx = compositePeriodIdx;
  3785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3786. {
  3787. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3788. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3789. (maxProfile.ChargingSchedule.Duration > 0))
  3790. {
  3791. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3792. {
  3793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3794. {
  3795. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3796. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3797. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3798. }
  3799. else
  3800. {
  3801. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3802. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3803. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3804. }
  3805. }
  3806. if(tmpPeriod.Limit != -1)
  3807. {
  3808. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3809. {
  3810. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3811. {
  3812. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3813. compositePeriodIdx++;
  3814. }
  3815. else
  3816. {
  3817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3818. }
  3819. }
  3820. // Delete duplicate period
  3821. if(compositePeriodIdx > 1)
  3822. {
  3823. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3824. {
  3825. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3826. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3827. compositePeriodIdx -= 1;
  3828. }
  3829. }
  3830. }
  3831. }
  3832. }
  3833. }
  3834. }
  3835. compositeProfile.ChargingSchedule.Duration = durationReq;
  3836. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3837. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3838. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3839. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3841. {
  3842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3843. {
  3844. compositeProfile.ChargingProfileId = 1;
  3845. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3846. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3847. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3848. }
  3849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3853. }
  3854. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3855. if(line)
  3856. free(line);
  3857. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3858. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3859. }
  3860. //==========================================
  3861. // Init all share memory
  3862. //==========================================
  3863. int InitShareMemory()
  3864. {
  3865. int result = PASS;
  3866. int MeterSMId;
  3867. //creat ShmSysConfigAndInfo
  3868. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3869. {
  3870. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3871. result = FAIL;
  3872. }
  3873. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3874. {
  3875. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3876. result = FAIL;
  3877. }
  3878. else
  3879. {}
  3880. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3881. {
  3882. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3883. result = FAIL;
  3884. }
  3885. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3886. {
  3887. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3888. result = FAIL;
  3889. }
  3890. else
  3891. {}
  3892. //creat ShmPsuData
  3893. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3894. {
  3895. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3899. {
  3900. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3901. result = FAIL;
  3902. }
  3903. else
  3904. {}
  3905. //creat ShmOCPP16Data
  3906. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3907. {
  3908. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3909. result = FAIL;
  3910. }
  3911. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3912. {
  3913. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3914. result = FAIL;
  3915. }
  3916. else
  3917. {}
  3918. /****************************** For Initial Settings************************************************/
  3919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3921. // allocate Configuration memory address
  3922. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3923. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3924. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3925. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3926. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3927. //offline MeterValue Interval
  3928. TempMeterValueInterval = 0;
  3929. return result;
  3930. }
  3931. int ProcessShareMemory()
  3932. {
  3933. int result = PASS;
  3934. if(InitShareMemory() == FAIL)
  3935. {
  3936. DEBUG_ERROR("InitShareMemory NG\n");
  3937. if(ShmStatusCodeData!=NULL)
  3938. {
  3939. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3940. }
  3941. result = FAIL;
  3942. }
  3943. // Model name parsing
  3944. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3945. {
  3946. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3947. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3948. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3949. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3950. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3951. ) // 'D' means DC
  3952. {
  3953. // DO series
  3954. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3955. {
  3956. gunTotalNumber += 1;
  3957. gunType[gun_index] = GUN_TYPE_DO;
  3958. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3959. {
  3960. case Gun_Type_Chademo:
  3961. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3962. break;
  3963. case Gun_Type_CCS_2:
  3964. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3965. break;
  3966. case Gun_Type_GB:
  3967. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3968. break;
  3969. case Gun_Type_AC:
  3970. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3971. break;
  3972. default:
  3973. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3974. break;
  3975. }
  3976. }
  3977. }
  3978. else
  3979. {
  3980. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3981. {
  3982. gunTotalNumber += 1;
  3983. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3984. {
  3985. case Gun_Type_Chademo:
  3986. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3987. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3988. break;
  3989. case Gun_Type_CCS_2:
  3990. gunType[gun_index] = GUN_TYPE_CCS;
  3991. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3992. break;
  3993. case Gun_Type_GB:
  3994. gunType[gun_index] = GUN_TYPE_GBT;
  3995. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3996. break;
  3997. case Gun_Type_AC:
  3998. gunType[gun_index] = GUN_TYPE_AC;
  3999. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4000. break;
  4001. default:
  4002. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4003. break;
  4004. }
  4005. }
  4006. }
  4007. }
  4008. else
  4009. {
  4010. DEBUG_ERROR("Model name parsing fail.\n");
  4011. result = FAIL;
  4012. }
  4013. if(result != PASS)sleep(5);
  4014. return result;
  4015. }
  4016. void checkRemoteStart(uint8_t connectorIdInt)
  4017. {
  4018. uint8_t tempIndex;
  4019. int result = PASS;
  4020. char cmdBuf[512];
  4021. //check Transaction active
  4022. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4023. {
  4024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4025. {
  4026. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4027. }
  4028. else
  4029. {
  4030. tempIndex = connectorIdInt -1;
  4031. }
  4032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4033. {
  4034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4035. {
  4036. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4037. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4038. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4039. {
  4040. //Reserved
  4041. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4042. }
  4043. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4044. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4045. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4046. {
  4047. //Reserved
  4048. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4049. result = FAIL;
  4050. goto end;
  4051. }
  4052. else
  4053. {
  4054. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4055. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4056. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4057. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4058. {
  4059. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4060. result = FAIL;
  4061. goto end;
  4062. }
  4063. }//END FOR ELSE
  4064. }
  4065. }// END FOR CHAdeMO_QUANTITY
  4066. }
  4067. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4070. {
  4071. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4072. }
  4073. else
  4074. {
  4075. tempIndex = connectorIdInt -1;
  4076. }
  4077. for (int index = 0; index < CCS_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4080. {
  4081. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4082. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4083. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4084. {
  4085. //Reserved
  4086. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4087. }
  4088. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4089. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4090. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4091. {
  4092. //Reserved
  4093. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4094. result = FAIL;
  4095. goto end;
  4096. }
  4097. else
  4098. {
  4099. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4100. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4101. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4102. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4103. {
  4104. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4105. result = FAIL;
  4106. goto end;
  4107. }
  4108. }// END FOR ELSE
  4109. }
  4110. }// END FOR CCS_QUANTITY
  4111. }
  4112. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4117. }
  4118. else
  4119. {
  4120. tempIndex = connectorIdInt -1;
  4121. }
  4122. for (int index = 0; index < GB_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4125. {
  4126. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4127. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4128. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4129. {
  4130. //Reserved
  4131. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4132. }
  4133. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4134. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4135. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4136. {
  4137. //Reserved
  4138. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4139. result = FAIL;
  4140. goto end;
  4141. }
  4142. else
  4143. {
  4144. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4145. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4146. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4148. {
  4149. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4150. result = FAIL;
  4151. goto end;
  4152. }
  4153. }// END FOR ELSE
  4154. }
  4155. } // END FOR GB_QUANTITY
  4156. }
  4157. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4158. {
  4159. tempIndex = connectorIdInt -1;
  4160. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4163. {
  4164. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4166. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4167. {
  4168. //Reserved
  4169. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4170. }
  4171. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4172. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4173. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4174. {
  4175. //Reserved
  4176. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4177. result = FAIL;
  4178. goto end;
  4179. }
  4180. else
  4181. {
  4182. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4183. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4184. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4185. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4186. {
  4187. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4188. result = FAIL;
  4189. goto end;
  4190. }
  4191. }// END FOR ELSE
  4192. }
  4193. } // END FOR GB_QUANTITY
  4194. }
  4195. else
  4196. {
  4197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4198. {
  4199. tempIndex = 2;
  4200. }
  4201. else
  4202. {
  4203. tempIndex = connectorIdInt -1;
  4204. }
  4205. for (int index = 0; index < AC_QUANTITY; index++)
  4206. {
  4207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4208. {
  4209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4210. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4211. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4212. {
  4213. //Reserved
  4214. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4215. }
  4216. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4217. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4219. {
  4220. //Reserved
  4221. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4222. result = FAIL;
  4223. goto end;
  4224. }
  4225. else
  4226. {
  4227. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4228. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4229. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4230. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4231. {
  4232. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4233. result = FAIL;
  4234. goto end;
  4235. }
  4236. }//END FOR ELSE
  4237. }
  4238. }// END FOR AC_QUANTITY
  4239. }
  4240. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4241. {
  4242. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4243. {
  4244. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4245. {
  4246. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4247. system(cmdBuf);
  4248. }
  4249. }
  4250. else
  4251. {
  4252. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4253. result = FAIL;
  4254. }
  4255. }
  4256. end:
  4257. if(result == PASS)
  4258. {
  4259. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4260. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4261. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4262. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4263. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4264. }
  4265. }
  4266. void CheckSystemValue(void)
  4267. {
  4268. char filenmae[100]={0};
  4269. char str[100]={0};
  4270. int tempIndex = 0;
  4271. //===============================
  4272. // send Heartbeat
  4273. //===============================
  4274. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4275. {
  4276. //parameter for test
  4277. sendHeartbeatRequest(0);
  4278. //===========================
  4279. // Reset Waiting Time
  4280. //===========================
  4281. HeartBeatWithNOResponse += 1;
  4282. }
  4283. //===============================
  4284. // Credit deduct report
  4285. //===============================
  4286. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4287. {
  4288. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4289. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4290. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4291. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4292. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4293. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4294. }
  4295. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4296. {
  4297. OCPP_query_deduct_info();
  4298. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4299. }
  4300. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4301. {
  4302. // ClockAlign MeterValue
  4303. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4304. {
  4305. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4306. {
  4307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4308. {
  4309. tempIndex = ((gun_index==2) ? 1: 0);
  4310. }
  4311. else
  4312. {
  4313. tempIndex = gun_index;
  4314. }
  4315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4316. {
  4317. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4318. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4319. {
  4320. reqClockAlignMeter[gun_index] = 1;
  4321. }
  4322. }// End for CHAdeMO
  4323. }
  4324. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4325. {
  4326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4327. {
  4328. tempIndex = ((gun_index==2) ? 1: 0);
  4329. }
  4330. else
  4331. {
  4332. tempIndex = gun_index;
  4333. }
  4334. for (int index = 0; index < CCS_QUANTITY; index++)
  4335. {
  4336. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4337. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4338. {
  4339. reqClockAlignMeter[gun_index] = 1;
  4340. }
  4341. } // End for CCS
  4342. }
  4343. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4346. {
  4347. tempIndex = ((gun_index==2) ? 1: 0);
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < GB_QUANTITY; index++)
  4354. {
  4355. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4356. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4357. {
  4358. reqClockAlignMeter[gun_index] = 1;
  4359. }
  4360. }// End for GB
  4361. }
  4362. else if(gunType[gun_index] == GUN_TYPE_DO)
  4363. {
  4364. tempIndex = gun_index;
  4365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4366. {
  4367. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4368. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4369. {
  4370. reqClockAlignMeter[gun_index] = 1;
  4371. }
  4372. }
  4373. }
  4374. else
  4375. {
  4376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4377. {
  4378. tempIndex = 2;
  4379. }
  4380. else
  4381. {
  4382. tempIndex = gun_index;
  4383. }
  4384. for (int index = 0; index < AC_QUANTITY; index++)
  4385. {
  4386. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4387. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. reqClockAlignMeter[gun_index] = 1;
  4390. }
  4391. }//End for AC
  4392. }
  4393. }
  4394. }
  4395. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4396. {
  4397. //==========================================
  4398. // Check remote start without connector id
  4399. //==========================================
  4400. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4401. {
  4402. int connectorIdInt = -1;
  4403. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4404. {
  4405. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4406. {
  4407. connectorIdInt = (gun_index+1);
  4408. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4409. checkRemoteStart(connectorIdInt);
  4410. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4411. break;
  4412. }
  4413. }
  4414. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4415. {
  4416. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4417. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4418. }
  4419. }
  4420. //==========================================
  4421. // csu trigger DataTransferReq
  4422. //==========================================
  4423. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4424. {
  4425. sendDataTransferRequest(gun_index);
  4426. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4427. }
  4428. //==========================================
  4429. // CSU Trigger Authorize Request
  4430. //==========================================
  4431. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4432. {
  4433. sendAuthorizeRequest(0);
  4434. authorizeRetryTimes = authorizeRetryTimes + 1;
  4435. if(authorizeRetryTimes < 3)
  4436. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4437. }
  4438. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4439. {
  4440. authorizeRetryTimes = 0;
  4441. SetOcppConnStatus(FALSE);
  4442. server_sign = FALSE;
  4443. }
  4444. 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))
  4445. {
  4446. sendAuthorizeRequest(0);
  4447. }
  4448. //==========================================
  4449. // Charger start transaction
  4450. //==========================================
  4451. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4452. {
  4453. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4454. sendStartTransactionRequest(gun_index);
  4455. refreshStartTimer(&clientTime.StartTransaction);
  4456. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4457. storeTempStopTransaction(gun_index);
  4458. }
  4459. //==========================================
  4460. // Charger stop transaction
  4461. //==========================================
  4462. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4463. {
  4464. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4465. sendStopTransactionRequest(gun_index);
  4466. OCPP_updatePeriodEnergy(gun_index);
  4467. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4468. refreshStartTimer(&clientTime.StopTransaction);
  4469. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4470. }
  4471. //==========================================
  4472. // Charger status report
  4473. //==========================================
  4474. //--- Check Mode Change ---//
  4475. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((gun_index==2) ? 1: 0);
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4487. {
  4488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4489. {
  4490. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4491. {
  4492. // Sent unplug message for California pricing logic
  4493. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4494. {
  4495. uint8_t ts[36];
  4496. getNowDatetime(ts);
  4497. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4498. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4499. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4500. sendUnplugByDataTransferRequest(gun_index);
  4501. interLock.isSentUnplug[gun_index] = 1;
  4502. }
  4503. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4504. {
  4505. interLock.isSentUnplug[gun_index] = 0;
  4506. }
  4507. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4508. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4509. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4510. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4511. {
  4512. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4513. if((access(filenmae,F_OK))!=-1)
  4514. {
  4515. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4516. sprintf(str,"rm -f %s",filenmae);
  4517. system(str);
  4518. }
  4519. }
  4520. }
  4521. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4522. #if 1 // for TempStopTransaction
  4523. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4524. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4525. {
  4526. checkTempStopTransaction(gun_index);
  4527. }
  4528. #endif
  4529. }
  4530. }
  4531. }
  4532. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4535. {
  4536. tempIndex = ((gun_index==2) ? 1: 0);
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < CCS_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4545. {
  4546. 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]*/ )
  4547. {
  4548. // Sent unplug message for California pricing logic
  4549. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4550. {
  4551. uint8_t ts[36];
  4552. getNowDatetime(ts);
  4553. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4554. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4555. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4556. sendUnplugByDataTransferRequest(gun_index);
  4557. interLock.isSentUnplug[gun_index] = 1;
  4558. }
  4559. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4560. {
  4561. interLock.isSentUnplug[gun_index] = 0;
  4562. }
  4563. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4564. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4565. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4566. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4567. {
  4568. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4569. if((access(filenmae,F_OK))!=-1)
  4570. {
  4571. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4572. sprintf(str,"rm -f %s",filenmae);
  4573. system(str);
  4574. }
  4575. }
  4576. }
  4577. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4578. #if 1 // for TempStopTransaction
  4579. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4580. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4581. {
  4582. checkTempStopTransaction(gun_index);
  4583. }
  4584. #endif
  4585. }
  4586. }
  4587. }
  4588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4591. {
  4592. tempIndex = ((gun_index==2) ? 1: 0);
  4593. }
  4594. else
  4595. {
  4596. tempIndex = gun_index;
  4597. }
  4598. for (int index = 0; index < GB_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4601. {
  4602. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4603. {
  4604. // Sent unplug message for California pricing logic
  4605. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4606. {
  4607. uint8_t ts[36];
  4608. getNowDatetime(ts);
  4609. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4610. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4611. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4612. sendUnplugByDataTransferRequest(gun_index);
  4613. interLock.isSentUnplug[gun_index] = 1;
  4614. }
  4615. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4616. {
  4617. interLock.isSentUnplug[gun_index] = 0;
  4618. }
  4619. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4620. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4621. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4622. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4623. {
  4624. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4625. if((access(filenmae,F_OK))!=-1)
  4626. {
  4627. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4628. sprintf(str,"rm -f %s",filenmae);
  4629. system(str);
  4630. }
  4631. }
  4632. }
  4633. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4634. #if 1 // for TempStopTransaction
  4635. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4636. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4637. {
  4638. checkTempStopTransaction(gun_index);
  4639. }
  4640. #endif
  4641. }
  4642. }
  4643. }
  4644. else if(gunType[gun_index] == GUN_TYPE_DO)
  4645. {
  4646. tempIndex = gun_index;
  4647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4650. {
  4651. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4652. {
  4653. // Sent unplug message for California pricing logic
  4654. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4655. {
  4656. uint8_t ts[36];
  4657. getNowDatetime(ts);
  4658. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4659. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4660. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4661. sendUnplugByDataTransferRequest(gun_index);
  4662. interLock.isSentUnplug[gun_index] = 1;
  4663. }
  4664. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4665. {
  4666. interLock.isSentUnplug[gun_index] = 0;
  4667. }
  4668. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4669. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4670. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4671. 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
  4672. {
  4673. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4674. if((access(filenmae,F_OK))!=-1)
  4675. {
  4676. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4677. sprintf(str,"rm -f %s",filenmae);
  4678. system(str);
  4679. }
  4680. }
  4681. }
  4682. 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);
  4683. #if 1 // for TempStopTransaction
  4684. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4685. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4686. {
  4687. checkTempStopTransaction(gun_index);
  4688. }
  4689. #endif
  4690. }
  4691. }
  4692. }
  4693. else
  4694. {
  4695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4696. {
  4697. tempIndex = 2;
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. for (int index = 0; index < AC_QUANTITY; index++)
  4704. {
  4705. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4706. {
  4707. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4708. {
  4709. // Sent unplug message for California pricing logic
  4710. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4711. {
  4712. uint8_t ts[36];
  4713. getNowDatetime(ts);
  4714. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4715. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4716. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4717. sendUnplugByDataTransferRequest(gun_index);
  4718. interLock.isSentUnplug[gun_index] = 1;
  4719. }
  4720. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4721. {
  4722. interLock.isSentUnplug[gun_index] = 0;
  4723. }
  4724. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4725. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4726. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4727. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4728. {
  4729. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4730. if((access(filenmae,F_OK))!=-1)
  4731. {
  4732. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4733. sprintf(str,"rm -f %s",filenmae);
  4734. system(str);
  4735. }
  4736. }
  4737. }
  4738. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4739. #if 1 // for TempStopTransaction
  4740. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4741. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4742. {
  4743. checkTempStopTransaction(gun_index);
  4744. }
  4745. #endif
  4746. }
  4747. }// END
  4748. }
  4749. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4750. (
  4751. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4752. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4753. )
  4754. )
  4755. {
  4756. sendStatusNotificationRequest(gun_index);
  4757. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4758. }
  4759. //==============================================
  4760. // TCCI reader status report
  4761. //==============================================
  4762. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4763. {
  4764. reportReaderStatus(gun_index);
  4765. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4766. }
  4767. //==============================================
  4768. // CSU Trigger Smart Charging Profile
  4769. //==============================================
  4770. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4771. {
  4772. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4773. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4774. }
  4775. //==============================================
  4776. // Meter report
  4777. //==============================================
  4778. // Trigger MeterValue
  4779. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4780. {
  4781. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4782. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4783. }
  4784. // Clock-aligned Meter value
  4785. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4786. {
  4787. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4788. reqClockAlignMeter[gun_index] = 0;
  4789. }
  4790. // Sample period MeterValue
  4791. 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))))
  4792. {
  4793. //check Transaction active
  4794. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4797. {
  4798. tempIndex = ((gun_index==2) ? 1: 0);
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4805. {
  4806. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4807. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4808. {
  4809. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4810. {
  4811. reqSampleMeter[gun_index] = 1;
  4812. }
  4813. }
  4814. }// End for CHAdeMO
  4815. }
  4816. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4817. {
  4818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4819. {
  4820. tempIndex = ((gun_index==2) ? 1: 0);
  4821. }
  4822. else
  4823. {
  4824. tempIndex = gun_index;
  4825. }
  4826. for (int index = 0; index < CCS_QUANTITY; index++)
  4827. {
  4828. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4829. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4832. {
  4833. reqSampleMeter[gun_index] = 1;
  4834. }
  4835. }
  4836. } // End for CCS
  4837. }
  4838. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4839. {
  4840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4841. {
  4842. tempIndex = ((gun_index==2) ? 1: 0);
  4843. }
  4844. else
  4845. {
  4846. tempIndex = gun_index;
  4847. }
  4848. for (int index = 0; index < GB_QUANTITY; index++)
  4849. {
  4850. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4851. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4852. {
  4853. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4854. {
  4855. reqSampleMeter[gun_index] = 1;
  4856. }
  4857. }
  4858. }// End for GB
  4859. }
  4860. else if(gunType[gun_index] == GUN_TYPE_DO)
  4861. {
  4862. tempIndex = gun_index;
  4863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4864. {
  4865. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4866. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4867. {
  4868. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4869. {
  4870. reqSampleMeter[gun_index] = 1;
  4871. }
  4872. }
  4873. }
  4874. }
  4875. else
  4876. {
  4877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4878. {
  4879. tempIndex = 2;
  4880. }
  4881. else
  4882. {
  4883. tempIndex = gun_index;
  4884. }
  4885. for (int index = 0; index < AC_QUANTITY; index++)
  4886. {
  4887. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4888. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4889. {
  4890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4891. {
  4892. reqSampleMeter[gun_index] = 1;
  4893. }
  4894. }
  4895. }//End for AC
  4896. }
  4897. if(reqSampleMeter[gun_index] == 1)
  4898. {
  4899. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4900. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4901. storeTempStopTransaction(gun_index);
  4902. reqSampleMeter[gun_index] = 0;
  4903. }
  4904. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4905. }
  4906. //==============================================
  4907. // Check Connector reserved
  4908. //==============================================
  4909. //===============================
  4910. // Check if Reserve is expired
  4911. //===============================
  4912. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4913. {
  4914. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4915. {
  4916. DEBUG_INFO("reserve expired.\n");
  4917. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4918. }
  4919. }//END OF Check if Reserve is expired
  4920. //==========================================
  4921. // csu trigger FirmwareStatusNotificationReq
  4922. //==========================================
  4923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4924. {
  4925. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4926. }
  4927. //==========================================
  4928. // csu trigger DiagnosticsStatusNotificationReq
  4929. //==========================================
  4930. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4931. {
  4932. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4933. }
  4934. //==========================================
  4935. // csu trigger CancelReservationConf
  4936. //==========================================
  4937. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4938. {
  4939. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4940. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4941. }
  4942. //==========================================
  4943. // csu trigger ChangeAvailabilityConf
  4944. //==========================================
  4945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4946. {
  4947. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4948. }
  4949. //==========================================
  4950. // csu trigger UnlockConnectorConf
  4951. //==========================================
  4952. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4953. {
  4954. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4955. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4956. }
  4957. //==========================================
  4958. // csu trigger ReserveNowConf
  4959. //==========================================
  4960. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4961. {
  4962. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4963. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4964. }
  4965. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4966. {
  4967. sendSignCertificateRequest();
  4968. }
  4969. }
  4970. }
  4971. //==========================================
  4972. // send request routine
  4973. //==========================================
  4974. int sendAuthorizeRequest(int gun_index)
  4975. {
  4976. mtrace();
  4977. int result = FAIL;
  4978. char message[100]={0};
  4979. char guid[37];
  4980. char tempdata[65]={0};
  4981. DEBUG_INFO("sendAuthorizeRequest...\n");
  4982. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4983. //Local Authorize
  4984. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4985. {
  4986. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4987. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4988. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4989. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4990. result = PASS;
  4991. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4992. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4993. authorizeRetryTimes = 0;
  4994. return result;
  4995. }
  4996. 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))||
  4997. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4998. {
  4999. // Query from cache
  5000. DEBUG_INFO("Authorize from cache.\n");
  5001. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5002. // Query from list
  5003. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5004. {
  5005. DEBUG_INFO("Authorize from list.\n");
  5006. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5007. }
  5008. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5009. {
  5010. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5011. {
  5012. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5013. }
  5014. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5015. {
  5016. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5017. }
  5018. if(!GetOcppConnStatus())
  5019. {
  5020. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5021. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5022. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5023. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5024. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5025. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5026. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5027. authorizeRetryTimes = 0;
  5028. return result;
  5029. }
  5030. }
  5031. else
  5032. {
  5033. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5034. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5035. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5036. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5037. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5038. else
  5039. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5040. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5041. result = PASS;
  5042. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5043. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5044. authorizeRetryTimes = 0;
  5045. return result;
  5046. }
  5047. }
  5048. //initialize struct Authorize
  5049. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5050. //get data from shared memory
  5051. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5052. random_uuid(guid);
  5053. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5054. LWS_Send(message);
  5055. sprintf(tempdata, "Authorize,%d", gun_index);
  5056. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5057. {
  5058. result = PASS;
  5059. DEBUG_INFO("Authorize mapItem pass\n");
  5060. }
  5061. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5062. return result;
  5063. }
  5064. int sendBootNotificationRequest(void)
  5065. {
  5066. mtrace();
  5067. int result = FAIL;
  5068. char message[500]={0}, payload[700]={0};
  5069. char guid[37]={0};
  5070. char tempdata[65]={0};
  5071. // Fill BootNotification fields
  5072. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5073. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5074. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5075. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5076. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5077. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5078. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5079. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5080. ShmOCPP16Data->ChargeBoxId
  5081. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5082. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5083. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5084. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5085. ,ShmOCPP16Data->BootNotification.CpIccid
  5086. ,ShmOCPP16Data->BootNotification.CpImsi);
  5087. random_uuid(guid);
  5088. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5089. LWS_Send(message);
  5090. sprintf(tempdata, "BootNotification,0");
  5091. 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*/)
  5092. {
  5093. result = PASS;
  5094. }
  5095. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5096. strcpy(queuedata,message);
  5097. return result;
  5098. }
  5099. int sendDataTransferRequest(int gun_index)
  5100. {
  5101. mtrace();
  5102. char message[1000]={0};
  5103. char guid[37]={0};
  5104. char tempdata[65]={0};
  5105. int result = FAIL;
  5106. random_uuid(guid);
  5107. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5108. MESSAGE_TYPE_CALL,
  5109. guid,
  5110. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5111. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5112. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5113. LWS_Send(message);
  5114. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5115. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5116. {
  5117. result = PASS;
  5118. DEBUG_INFO("DataTransfer mapItem pass\n");
  5119. }
  5120. return result;
  5121. }
  5122. int sendUnplugByDataTransferRequest(int gun_index)
  5123. {
  5124. mtrace();
  5125. char message[1000]={0};
  5126. char guid[37]={0};
  5127. char tempdata[65]={0};
  5128. int result = FAIL;
  5129. random_uuid(guid);
  5130. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5131. (gun_index+1),
  5132. MESSAGE_TYPE_CALL,
  5133. guid,
  5134. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5135. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5136. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5137. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5138. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5139. {
  5140. result = PASS;
  5141. DEBUG_INFO("DataTransfer mapItem pass\n");
  5142. }
  5143. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5144. return result;
  5145. }
  5146. int sendDiagnosticsStatusNotificationRequest(char *status)
  5147. {
  5148. mtrace();
  5149. int result = FAIL;
  5150. char message[110]={0};
  5151. char guid[37]={0};
  5152. char tempdata[65]={0};
  5153. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5154. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5155. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5156. random_uuid(guid);
  5157. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5158. LWS_SendNow(message);
  5159. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5160. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5161. {
  5162. result = PASS;
  5163. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5164. }
  5165. //#ifdef SystemLogMessage
  5166. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5167. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5168. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5169. //#endif
  5170. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5171. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5172. //record status
  5173. if(strcmp(status,"Idle")==0)
  5174. {
  5175. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5176. }
  5177. else if(strcmp(status,"Uploaded")==0)
  5178. {
  5179. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5180. }
  5181. else if(strcmp(status,"UploadFailed")==0)
  5182. {
  5183. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5184. }
  5185. else if(strcmp(status,"Uploading")==0)
  5186. {
  5187. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5188. }
  5189. return result;
  5190. }
  5191. int sendFirmwareStatusNotificationRequest(char *status)
  5192. {
  5193. mtrace();
  5194. int result = FAIL;
  5195. char message[110]={0};
  5196. char guid[37]={0};
  5197. char tempdata[65]={0};
  5198. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5199. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5200. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5201. random_uuid(guid);
  5202. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5203. LWS_SendNow(message);
  5204. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5205. 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*/)
  5206. {
  5207. result = PASS;
  5208. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5209. }
  5210. //#ifdef SystemLogMessage
  5211. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5212. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5213. //#endif
  5214. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5215. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5216. //record status
  5217. if(strcmp(status,"Downloaded")==0)
  5218. {
  5219. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5220. }
  5221. else if(strcmp(status,"DownloadFailed")==0)
  5222. {
  5223. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5224. }
  5225. else if(strcmp(status,"Downloading")==0)
  5226. {
  5227. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5228. }
  5229. else if(strcmp(status,"Idle")==0)
  5230. {
  5231. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5232. }
  5233. else if(strcmp(status,"InstallationFailed")==0)
  5234. {
  5235. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5236. }
  5237. else if(strcmp(status,"Installing")==0)
  5238. {
  5239. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5240. }
  5241. else if(strcmp(status,"Installed")==0)
  5242. {
  5243. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5244. }
  5245. return result;
  5246. }
  5247. int sendHeartbeatRequest(int gun_index)
  5248. {
  5249. mtrace();
  5250. int result = FAIL;
  5251. char message[80]={0};
  5252. char guid[37]={0};
  5253. char tempdata[65]={0};
  5254. random_uuid(guid);
  5255. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5256. , MESSAGE_TYPE_CALL
  5257. , guid );
  5258. LWS_Send(message);
  5259. sprintf(tempdata, "Heartbeat,%d", 0);
  5260. 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*/)
  5261. {
  5262. result = PASS;
  5263. }
  5264. return result;
  5265. }
  5266. int sendStartTransactionRequest(int gun_index)
  5267. {
  5268. mtrace();
  5269. int result = FAIL;
  5270. char message[250]={0};
  5271. char guid[37]={0};
  5272. struct timeval tmnow;
  5273. struct tm *tm;
  5274. char buf[28];//, usec_buf[6];
  5275. char tempdata[65]={0};
  5276. int tempIndex = 0;
  5277. DEBUG_INFO("sendStartTransactionRequest...\n");
  5278. gettimeofday(&tmnow, NULL);
  5279. time_t t;
  5280. t = time(NULL);
  5281. /*UTC time and date*/
  5282. tm = gmtime(&t);
  5283. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5284. #if 0 // remove temporally
  5285. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5286. strcat(buf,".");
  5287. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5288. strcat(buf,usec_buf);
  5289. #endif
  5290. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5291. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5292. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5293. // clear StartTransaction Response
  5294. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5295. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5296. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5297. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5298. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5299. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5300. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5301. {
  5302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5303. {
  5304. tempIndex = ((gun_index==2) ? 1: 0);
  5305. }
  5306. else
  5307. {
  5308. tempIndex = gun_index;
  5309. }
  5310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5313. {
  5314. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5315. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5316. }
  5317. }
  5318. }
  5319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5320. {
  5321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5322. {
  5323. tempIndex = ((gun_index==2) ? 1: 0);
  5324. }
  5325. else
  5326. {
  5327. tempIndex = gun_index;
  5328. }
  5329. for (int index = 0; index < CCS_QUANTITY; index++)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5332. {
  5333. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5334. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5335. }
  5336. }
  5337. }
  5338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5339. {
  5340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5341. {
  5342. tempIndex = ((gun_index==2) ? 1: 0);
  5343. }
  5344. else
  5345. {
  5346. tempIndex = gun_index;
  5347. }
  5348. for (int index = 0; index < GB_QUANTITY; index++)
  5349. {
  5350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5351. {
  5352. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5353. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5354. }
  5355. }
  5356. }
  5357. else if(gunType[gun_index] == GUN_TYPE_DO)
  5358. {
  5359. tempIndex = gun_index;
  5360. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5363. {
  5364. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5365. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5366. }
  5367. }
  5368. }
  5369. else
  5370. {
  5371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5372. {
  5373. tempIndex = 2;
  5374. }
  5375. else
  5376. {
  5377. tempIndex = gun_index;
  5378. }
  5379. for (int index = 0; index < AC_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5382. {
  5383. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5384. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5385. }
  5386. }
  5387. }
  5388. random_uuid(guid);
  5389. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5390. {
  5391. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5392. , gun_index +1
  5393. , MESSAGE_TYPE_CALL
  5394. , guid
  5395. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5396. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5397. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5398. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5399. }
  5400. else
  5401. {
  5402. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5403. , gun_index +1
  5404. , MESSAGE_TYPE_CALL
  5405. , guid
  5406. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5407. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5408. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5409. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5410. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5411. }
  5412. #if 1
  5413. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5414. 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*/)
  5415. {
  5416. result = PASS;
  5417. }
  5418. #endif
  5419. strcpy(queuedata, message);
  5420. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5421. OCPP_insert_transaction_msg(YES, queuedata);
  5422. return result;
  5423. }
  5424. int sendStatusNotificationRequest(int gun_index)
  5425. {
  5426. mtrace();
  5427. int result = FAIL;
  5428. char message[600]={0};
  5429. char guid[37];
  5430. int currentStatus = 0;
  5431. struct timeval tmnow;
  5432. struct tm *tm;
  5433. char buf[28];//, usec_buf[6];
  5434. char tempdata[65]={0};
  5435. int tempIndex = 0;
  5436. uint8_t isStateChanged = TRUE;
  5437. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5438. gettimeofday(&tmnow, NULL);
  5439. time_t t;
  5440. t = time(NULL);
  5441. /*UTC time and date*/
  5442. tm = gmtime(&t);
  5443. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5444. #if 0 // remove temporally
  5445. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5446. strcat(buf,".");
  5447. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5448. strcat(buf,usec_buf);
  5449. #endif
  5450. //printf("%s",buf);
  5451. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5452. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5453. // it's option
  5454. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5455. /*
  5456. enum _SYSTEM_STATUS
  5457. {
  5458. S_BOOTING = 0,
  5459. S_IDLE, = 1
  5460. S_AUTHORIZING, =2
  5461. S_REASSIGN_CHECK, =3
  5462. S_REASSIGN, =4
  5463. S_PRECHARGE, =5
  5464. S_PREPARING_FOR_EV, =6
  5465. S_PREPARING_FOR_EVSE, =7
  5466. S_CHARGING, =8
  5467. S_TERMINATING, =9
  5468. S_COMPLETE, =10
  5469. S_ALARM, =11
  5470. S_FAULT =12
  5471. }
  5472. */
  5473. //check Transaction active
  5474. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5475. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5476. {
  5477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5478. {
  5479. tempIndex = ((gun_index==2) ? 1: 0);
  5480. }
  5481. else
  5482. {
  5483. tempIndex = gun_index;
  5484. }
  5485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5486. {
  5487. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5488. {
  5489. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5490. {
  5491. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5492. {
  5493. currentStatus = Preparing; //OCPP Status: Preparing
  5494. }
  5495. else
  5496. {
  5497. currentStatus = Available; //OCPP Status: Available
  5498. }
  5499. }
  5500. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5501. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5502. ) //S_PRECHARGE
  5503. {
  5504. currentStatus = Preparing; //OCPP Status: Preparing
  5505. }
  5506. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5507. {
  5508. currentStatus = Charging; //OCPP Status: Charging
  5509. }
  5510. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5511. {
  5512. currentStatus = Finishing; //OCPP Status: Finishing
  5513. }
  5514. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5515. {
  5516. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5517. }
  5518. 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
  5519. {
  5520. currentStatus = Unavailable; //OCPP Status: Unavailable
  5521. }
  5522. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5523. {
  5524. currentStatus = Faulted; //OCPP Status: Faulted
  5525. }
  5526. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5527. {
  5528. currentStatus = Reserved; //OCPP Status: Reserved
  5529. }
  5530. } //end of the same index
  5531. }//end of for CHAdeMO_QUANTITY
  5532. }
  5533. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5534. {
  5535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5536. {
  5537. tempIndex = ((gun_index==2) ? 1: 0);
  5538. }
  5539. else
  5540. {
  5541. tempIndex = gun_index;
  5542. }
  5543. for (int index = 0; index < CCS_QUANTITY; index++)
  5544. {
  5545. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5548. {
  5549. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5550. {
  5551. currentStatus = Preparing; //OCPP Status: Preparing
  5552. }
  5553. else
  5554. {
  5555. currentStatus = Available; //OCPP Status: Available
  5556. }
  5557. }
  5558. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5559. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5560. ) //S_PRECHARGE
  5561. {
  5562. currentStatus = Preparing; //OCPP Status: Preparing
  5563. }
  5564. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5565. {
  5566. currentStatus = Charging; //OCPP Status: Charging
  5567. }
  5568. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5569. {
  5570. currentStatus = Finishing; //OCPP Status: Finishing
  5571. }
  5572. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5573. {
  5574. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5575. }
  5576. 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
  5577. {
  5578. currentStatus = Unavailable; //OCPP Status : Unavailable
  5579. }
  5580. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5581. {
  5582. currentStatus = Faulted; //OCPP Status: Faulted
  5583. }
  5584. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5585. {
  5586. currentStatus = Reserved; //OCPP Status: Reserved
  5587. }
  5588. } //end of the same index
  5589. } // end of for CCS_QUANTITY
  5590. }
  5591. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5592. {
  5593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5594. {
  5595. tempIndex = ((gun_index==2) ? 1: 0);
  5596. }
  5597. else
  5598. {
  5599. tempIndex = gun_index;
  5600. }
  5601. for (int index = 0; index < GB_QUANTITY; index++)
  5602. {
  5603. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5604. {
  5605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5606. {
  5607. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5608. {
  5609. currentStatus = Preparing; //OCPP Status: Preparing
  5610. }
  5611. else
  5612. {
  5613. currentStatus = Available; //OCPP Status: Available
  5614. }
  5615. }
  5616. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5617. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5618. ) //S_PRECHARGE
  5619. {
  5620. currentStatus = Preparing; //OCPP Status: Preparing
  5621. }
  5622. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5623. {
  5624. currentStatus = Charging; //OCPP Status: Charging
  5625. }
  5626. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5627. {
  5628. currentStatus = Finishing; //OCPP Status: Finishing
  5629. }
  5630. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5631. {
  5632. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5633. }
  5634. 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
  5635. {
  5636. currentStatus = Unavailable; //OCPP Status: Unavailable
  5637. }
  5638. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5639. {
  5640. currentStatus = Faulted; //OCPP Status: Faulted
  5641. }
  5642. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5643. {
  5644. currentStatus = Reserved; //OCPP Status: Reserved
  5645. }
  5646. } //end of the same index
  5647. } // end of for GB_QUANTITY
  5648. }
  5649. else if(gunType[gun_index] == GUN_TYPE_DO)
  5650. {
  5651. tempIndex = gun_index;
  5652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5653. {
  5654. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5655. {
  5656. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5657. {
  5658. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5659. {
  5660. currentStatus = Preparing; //OCPP Status: Preparing
  5661. }
  5662. else
  5663. {
  5664. currentStatus = Available; //OCPP Status: Available
  5665. }
  5666. }
  5667. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5668. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5669. ) //S_PRECHARGE
  5670. {
  5671. currentStatus = Preparing; //OCPP Status: Preparing
  5672. }
  5673. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5674. {
  5675. currentStatus = Charging; //OCPP Status: Charging
  5676. }
  5677. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5678. {
  5679. currentStatus = Finishing; //OCPP Status: Finishing
  5680. }
  5681. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5682. {
  5683. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5684. }
  5685. 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
  5686. {
  5687. currentStatus = Unavailable; //OCPP Status: Unavailable
  5688. }
  5689. 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
  5690. {
  5691. currentStatus = Faulted; //OCPP Status: Faulted
  5692. }
  5693. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5694. {
  5695. currentStatus = Reserved; //OCPP Status: Reserved
  5696. }
  5697. } //end of the same index
  5698. }
  5699. }
  5700. else
  5701. {
  5702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5703. {
  5704. tempIndex = 2;
  5705. }
  5706. else
  5707. {
  5708. tempIndex = gun_index;
  5709. }
  5710. for (int index = 0; index < AC_QUANTITY; index++)
  5711. {
  5712. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5713. {
  5714. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5715. {
  5716. 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))
  5717. {
  5718. currentStatus = Preparing; //OCPP Status: Preparing
  5719. }
  5720. else
  5721. {
  5722. currentStatus = Available; //OCPP Status: Available
  5723. }
  5724. }
  5725. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5726. {
  5727. currentStatus = Preparing; //OCPP Status: Preparing
  5728. }
  5729. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5730. {
  5731. currentStatus = Charging; //OCPP Status: Charging
  5732. }
  5733. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5734. {
  5735. currentStatus = Finishing; //OCPP Status: Finishing
  5736. }
  5737. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5738. {
  5739. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5740. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5741. else
  5742. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5743. }
  5744. 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
  5745. {
  5746. currentStatus = Unavailable; //OCPP Status: Unavailable
  5747. }
  5748. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5749. {
  5750. currentStatus = Faulted; //OCPP Status: Faulted
  5751. }
  5752. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5753. {
  5754. currentStatus = Reserved; //OCPP Status: Reserved
  5755. }
  5756. }//end of the same index
  5757. }//end of for AC_QUANTITY
  5758. }
  5759. //it's option
  5760. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5761. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5762. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5763. {
  5764. isStateChanged = FALSE;
  5765. }
  5766. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5767. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5768. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5769. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5770. random_uuid(guid);
  5771. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5772. , MESSAGE_TYPE_CALL
  5773. , guid
  5774. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5775. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5776. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5777. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5778. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5779. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5780. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5781. if((server_sign == TRUE) && isStateChanged)
  5782. {
  5783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5784. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5785. LWS_Send(message);
  5786. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5787. 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*/)
  5788. {
  5789. //DEBUG_ERROR("statusNotification mapitem pass");
  5790. result = PASS;
  5791. }
  5792. }
  5793. else
  5794. {
  5795. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5796. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5797. result = PASS;
  5798. }
  5799. return result;
  5800. }
  5801. int sendStopTransactionRequest(int gun_index)
  5802. {
  5803. mtrace();
  5804. int result = FAIL;
  5805. //char message[1500]={0};
  5806. char guid[37]={0};
  5807. char tempdata[65]={0};
  5808. int tempIndex = 0;
  5809. char TempStopTransaction[256];
  5810. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5811. //int idx_sample=0;
  5812. DEBUG_INFO("sendStopTransactionRequest \n");
  5813. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5814. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5815. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5816. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5817. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5818. {
  5819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5820. {
  5821. tempIndex = ((gun_index==2) ? 1: 0);
  5822. }
  5823. else
  5824. {
  5825. tempIndex = gun_index;
  5826. }
  5827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5828. {
  5829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5830. {
  5831. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5832. }
  5833. }// END OF CHAdeMO_QUANTITY
  5834. }
  5835. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5836. {
  5837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5838. {
  5839. tempIndex = ((gun_index==2) ? 1: 0);
  5840. }
  5841. else
  5842. {
  5843. tempIndex = gun_index;
  5844. }
  5845. for (int index = 0; index < CCS_QUANTITY; index++)
  5846. {
  5847. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5848. {
  5849. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5850. }
  5851. }// END OF CCS_QUANTITY
  5852. }
  5853. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5854. {
  5855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5856. {
  5857. tempIndex = ((gun_index==2) ? 1: 0);
  5858. }
  5859. else
  5860. {
  5861. tempIndex = gun_index;
  5862. }
  5863. for (int index = 0; index < GB_QUANTITY; index++)
  5864. {
  5865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5866. {
  5867. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5868. }
  5869. }// END OF GB_QUANTITY
  5870. }
  5871. else if(gunType[gun_index] == GUN_TYPE_DO)
  5872. {
  5873. tempIndex = gun_index;
  5874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5877. {
  5878. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5879. }
  5880. }// END OF GB_QUANTITY
  5881. }
  5882. else
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5885. {
  5886. tempIndex = 2;
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < AC_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5895. {
  5896. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5897. }
  5898. }// END OF AC_QUANTITY
  5899. }
  5900. //====================================== Stop Transaction Time =====================================================
  5901. struct timeval tmnow;
  5902. struct tm *tm;
  5903. char buf[28];//, usec_buf[6];
  5904. gettimeofday(&tmnow, NULL);
  5905. time_t t;
  5906. t = time(NULL);
  5907. /*UTC time and date*/
  5908. tm = gmtime(&t);
  5909. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5911. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5912. random_uuid(guid);
  5913. /***********************************transactionData******************************************************/
  5914. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5916. //=================================
  5917. // Transaction_Begin
  5918. //=================================
  5919. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5920. {
  5921. //============================================ Energy.Active.Import.Interval ================================
  5922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5927. 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))
  5928. {
  5929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5930. }
  5931. else
  5932. {
  5933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5934. }
  5935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5937. }
  5938. //=================================
  5939. // Transaction_End
  5940. //=================================
  5941. // ================================= Current.Import L1 ===============================================
  5942. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5943. {
  5944. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5945. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5946. {
  5947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5948. {
  5949. tempIndex = ((gun_index==2) ? 1: 0);
  5950. }
  5951. else
  5952. {
  5953. tempIndex = gun_index;
  5954. }
  5955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5958. {
  5959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5960. }
  5961. }// End of for CHAdeMO_QUANTITY
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5963. }
  5964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5965. {
  5966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5967. {
  5968. tempIndex = ((gun_index==2) ? 1: 0);
  5969. }
  5970. else
  5971. {
  5972. tempIndex = gun_index;
  5973. }
  5974. for (int index = 0; index < CCS_QUANTITY; index++)
  5975. {
  5976. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5977. {
  5978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5979. }
  5980. }// End of for CCS_QUANTITY
  5981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5982. }
  5983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5984. {
  5985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5986. {
  5987. tempIndex = ((gun_index==2) ? 1: 0);
  5988. }
  5989. else
  5990. {
  5991. tempIndex = gun_index;
  5992. }
  5993. for (int index = 0; index < GB_QUANTITY; index++)
  5994. {
  5995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5996. {
  5997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5998. }
  5999. }// End of for GB_QUANTITY
  6000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6001. }
  6002. else if(gunType[gun_index] == GUN_TYPE_DO)
  6003. {
  6004. tempIndex = gun_index;
  6005. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6010. }
  6011. }
  6012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6013. }
  6014. else
  6015. {
  6016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6017. {
  6018. tempIndex = 2;
  6019. }
  6020. else
  6021. {
  6022. tempIndex = gun_index;
  6023. }
  6024. for (int index = 0; index < AC_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6027. {
  6028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6029. }
  6030. }// End of for AC_QUANTITY
  6031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6032. }
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6038. }
  6039. // ================================= Energy.Active.Import.Interval ==============================================
  6040. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6041. {
  6042. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6044. {
  6045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6046. {
  6047. tempIndex = ((gun_index==2) ? 1: 0);
  6048. }
  6049. else
  6050. {
  6051. tempIndex = gun_index;
  6052. }
  6053. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6054. {
  6055. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6056. {
  6057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6058. }
  6059. }// END OF CHAdeMO_QUANTITY
  6060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6061. }
  6062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6063. {
  6064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6065. {
  6066. tempIndex = ((gun_index==2) ? 1: 0);
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. for (int index = 0; index < CCS_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6077. }
  6078. }// END OF CCS_QUANTITY
  6079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6080. }
  6081. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6082. {
  6083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6084. {
  6085. tempIndex = ((gun_index==2) ? 1: 0);
  6086. }
  6087. else
  6088. {
  6089. tempIndex = gun_index;
  6090. }
  6091. for (int index = 0; index < GB_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6094. {
  6095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6096. }
  6097. }// END OF GB_QUANTITY
  6098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6099. }
  6100. else if(gunType[gun_index] == GUN_TYPE_DO)
  6101. {
  6102. tempIndex = gun_index;
  6103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6108. }
  6109. }
  6110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6111. }
  6112. else
  6113. {
  6114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6115. {
  6116. tempIndex = 2;
  6117. }
  6118. else
  6119. {
  6120. tempIndex = gun_index;
  6121. }
  6122. for (int index = 0; index < AC_QUANTITY; index++)
  6123. {
  6124. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6125. {
  6126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6127. }
  6128. }// END OF AC_QUANTITY
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6130. }
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6136. }
  6137. //=================================== Power.Active.Import ==================================================
  6138. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6139. {
  6140. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6142. {
  6143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6144. {
  6145. tempIndex = ((gun_index==2) ? 1: 0);
  6146. }
  6147. else
  6148. {
  6149. tempIndex = gun_index;
  6150. }
  6151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6152. {
  6153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6154. {
  6155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6156. }
  6157. } // End for CHAdeMO_QUANTITY
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6159. }
  6160. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6161. {
  6162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6163. {
  6164. tempIndex = ((gun_index==2) ? 1: 0);
  6165. }
  6166. else
  6167. {
  6168. tempIndex = gun_index;
  6169. }
  6170. for (int index = 0; index < CCS_QUANTITY; index++)
  6171. {
  6172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6173. {
  6174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6175. }
  6176. } // END for CCS_QUANTITY
  6177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6178. }
  6179. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6180. {
  6181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6182. {
  6183. tempIndex = ((gun_index==2) ? 1: 0);
  6184. }
  6185. else
  6186. {
  6187. tempIndex = gun_index;
  6188. }
  6189. for (int index = 0; index < GB_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6192. {
  6193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6194. }
  6195. }// END for GB_QUANTITY
  6196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6197. }
  6198. else if(gunType[gun_index] == GUN_TYPE_DO)
  6199. {
  6200. tempIndex = gun_index;
  6201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6202. {
  6203. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6204. {
  6205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6206. }
  6207. }
  6208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6209. }
  6210. else
  6211. {
  6212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6213. {
  6214. tempIndex = 2;
  6215. }
  6216. else
  6217. {
  6218. tempIndex = gun_index;
  6219. }
  6220. for (int index = 0; index < AC_QUANTITY; index++)
  6221. {
  6222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6223. {
  6224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6225. }
  6226. } // END for AC_QUANTITY
  6227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6228. }
  6229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6234. }
  6235. //============================ Voltage L1 ====================================
  6236. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6237. {
  6238. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6239. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6240. {
  6241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6242. {
  6243. tempIndex = ((gun_index==2) ? 1: 0);
  6244. }
  6245. else
  6246. {
  6247. tempIndex = gun_index;
  6248. }
  6249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6254. }
  6255. } // END OF FOR CHAdeMO_QUANTITY
  6256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6257. }
  6258. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6261. {
  6262. tempIndex = ((gun_index==2) ? 1: 0);
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < CCS_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6271. {
  6272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6273. }
  6274. } // END OF FOR CCS_QUANTITY
  6275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6276. }
  6277. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6278. {
  6279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6280. {
  6281. tempIndex = ((gun_index==2) ? 1: 0);
  6282. }
  6283. else
  6284. {
  6285. tempIndex = gun_index;
  6286. }
  6287. for (int index = 0; index < GB_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6290. {
  6291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6292. }
  6293. } // END OF FOR GB_QUANTITY
  6294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6295. }
  6296. else if(gunType[gun_index] == GUN_TYPE_DO)
  6297. {
  6298. tempIndex = gun_index;
  6299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6307. }
  6308. else
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6311. {
  6312. tempIndex = 2;
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < AC_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6321. {
  6322. 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
  6323. }
  6324. } // END OF FOR AC_QUANTITY
  6325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6326. }
  6327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6332. }
  6333. //====================== End SoC ================================
  6334. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6335. {
  6336. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6337. 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))
  6338. {
  6339. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6340. {
  6341. tempIndex = ((gun_index==2) ? 1: 0);
  6342. }
  6343. else
  6344. {
  6345. tempIndex = gun_index;
  6346. }
  6347. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6348. {
  6349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6354. }
  6355. }
  6356. }
  6357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6358. {
  6359. for (int index = 0; index < CCS_QUANTITY; index++)
  6360. {
  6361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6362. {
  6363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6364. }
  6365. }
  6366. }
  6367. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6368. {
  6369. for (int index = 0; index < GB_QUANTITY; index++)
  6370. {
  6371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6372. {
  6373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6374. }
  6375. }
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_DO)
  6378. {
  6379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6384. }
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6393. } // END FOR DC CASE
  6394. }
  6395. // ================================= Current.Import L2 ===============================================
  6396. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6397. {
  6398. // AC 3 phse L2 current
  6399. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6400. {
  6401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6402. {
  6403. tempIndex = 2;
  6404. }
  6405. else
  6406. {
  6407. tempIndex = gun_index;
  6408. }
  6409. for (int index = 0; index < AC_QUANTITY; index++)
  6410. {
  6411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6412. {
  6413. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6414. }
  6415. }// End of for AC_QUANTITY
  6416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6417. }
  6418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6423. }
  6424. // ================================= Current.Import L3 ===============================================
  6425. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6426. {
  6427. // AC 3 phse L3 current
  6428. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6429. {
  6430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6431. {
  6432. tempIndex = 2;
  6433. }
  6434. else
  6435. {
  6436. tempIndex = gun_index;
  6437. }
  6438. for (int index = 0; index < AC_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6441. {
  6442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6443. }
  6444. }// End of for AC_QUANTITY
  6445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6446. }
  6447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6452. }
  6453. //============================ Voltage L2 ====================================
  6454. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6455. {
  6456. // AC 3 phse L2 voltage
  6457. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6458. {
  6459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6460. {
  6461. tempIndex = 2;
  6462. }
  6463. else
  6464. {
  6465. tempIndex = gun_index;
  6466. }
  6467. for (int index = 0; index < AC_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6470. {
  6471. 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
  6472. }
  6473. } // END OF FOR AC_QUANTITY
  6474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6475. }
  6476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6481. }
  6482. //============================ Voltage L3 ====================================
  6483. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6484. {
  6485. // AC 3 phse L3 voltage
  6486. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6487. {
  6488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6489. {
  6490. tempIndex = 2;
  6491. }
  6492. else
  6493. {
  6494. tempIndex = gun_index;
  6495. }
  6496. for (int index = 0; index < AC_QUANTITY; index++)
  6497. {
  6498. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6499. {
  6500. 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
  6501. }
  6502. } // END OF FOR AC_QUANTITY
  6503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6504. }
  6505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6510. }
  6511. //====================== Start SoC ================================
  6512. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6513. {
  6514. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6515. 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))
  6516. {
  6517. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6518. {
  6519. tempIndex = ((gun_index==2) ? 1: 0);
  6520. }
  6521. else
  6522. {
  6523. tempIndex = gun_index;
  6524. }
  6525. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6526. {
  6527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6528. {
  6529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6530. {
  6531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6532. }
  6533. }
  6534. }
  6535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6536. {
  6537. for (int index = 0; index < CCS_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6540. {
  6541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6542. }
  6543. }
  6544. }
  6545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6546. {
  6547. for (int index = 0; index < GB_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6550. {
  6551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6552. }
  6553. }
  6554. }
  6555. else if(gunType[gun_index] == GUN_TYPE_DO)
  6556. {
  6557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6558. {
  6559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6560. {
  6561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6562. }
  6563. }
  6564. }
  6565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6571. } // END FOR DC CASE
  6572. }
  6573. //================================================ Message create ====================================================
  6574. json_object *StopTransaction = json_object_new_object();
  6575. json_object *transactionDatas = json_object_new_array();
  6576. json_object *sampledValues = json_object_new_array();
  6577. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6578. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6579. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6580. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6581. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6582. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6583. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6584. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6585. {
  6586. json_object *transactionData = json_object_new_object();
  6587. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6588. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6589. {
  6590. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6591. {
  6592. json_object *sampledValue = json_object_new_object();
  6593. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6594. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6595. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6596. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6597. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6598. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6599. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6600. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6601. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6602. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6603. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6604. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6605. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6606. json_object_array_add(sampledValues, sampledValue);
  6607. }
  6608. }
  6609. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6610. json_object_array_add(transactionDatas, transactionData);
  6611. }
  6612. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6613. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6614. ,MESSAGE_TYPE_CALL
  6615. ,guid
  6616. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6617. json_object_put(StopTransaction);
  6618. #if 1 // for TempStopTransaction
  6619. //Delete TempStopTransaction
  6620. if((access(TempStopTransaction,F_OK))!=-1)
  6621. {
  6622. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6623. }
  6624. #endif
  6625. #if 1
  6626. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6627. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6628. {
  6629. result = PASS;
  6630. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6631. }
  6632. #endif
  6633. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6634. OCPP_insert_transaction_msg(NO, queuedata);
  6635. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6636. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6637. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6638. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6639. {
  6640. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6641. }
  6642. //for test
  6643. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6644. return result;
  6645. }
  6646. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6647. {
  6648. mtrace();
  6649. int result = FAIL;
  6650. char guid[37]={0};
  6651. char tempdata[65]={0};
  6652. int tempIndex = 0;
  6653. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6654. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6655. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6656. //set value
  6657. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6658. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6659. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6660. -1);
  6661. random_uuid(guid);
  6662. //UTC Date time
  6663. struct timeval tmnow;
  6664. struct tm *tm;
  6665. char buf[28];//, usec_buf[6];
  6666. gettimeofday(&tmnow, NULL);
  6667. time_t t;
  6668. t = time(NULL);
  6669. /*UTC time and date*/
  6670. tm = gmtime(&t);
  6671. if(dataType == ReadingContext_Sample_Clock)
  6672. {
  6673. struct tm *tmTarget;
  6674. struct timeb tbTarget;
  6675. tbTarget.time = mktime(tm);
  6676. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6677. tmTarget = gmtime(&tbTarget.time);
  6678. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6679. }
  6680. else
  6681. {
  6682. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6683. }
  6684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6685. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6686. //********************************(1)Current.Import L1************************************************/
  6687. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6688. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6689. (dataType == ReadingContext_Trigger))
  6690. {
  6691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6693. {
  6694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6695. {
  6696. tempIndex = ((gun_index==2) ? 1: 0);
  6697. }
  6698. else
  6699. {
  6700. tempIndex = gun_index;
  6701. }
  6702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6703. {
  6704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6705. {
  6706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6707. }
  6708. }
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6710. }
  6711. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6712. {
  6713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6714. {
  6715. tempIndex = ((gun_index==2) ? 1: 0);
  6716. }
  6717. else
  6718. {
  6719. tempIndex = gun_index;
  6720. }
  6721. for (int index = 0; index < CCS_QUANTITY; index++)
  6722. {
  6723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6724. {
  6725. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6726. }
  6727. }
  6728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6729. }
  6730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6731. {
  6732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6733. {
  6734. tempIndex = ((gun_index==2) ? 1: 0);
  6735. }
  6736. else
  6737. {
  6738. tempIndex = gun_index;
  6739. }
  6740. for (int index = 0; index < GB_QUANTITY; index++)
  6741. {
  6742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6743. {
  6744. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6745. }
  6746. }
  6747. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6748. }
  6749. else if(gunType[gun_index] == GUN_TYPE_DO)
  6750. {
  6751. tempIndex = gun_index;
  6752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6753. {
  6754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6755. {
  6756. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6757. }
  6758. }
  6759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6760. }
  6761. else
  6762. {
  6763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6764. {
  6765. tempIndex = 2;
  6766. }
  6767. else
  6768. {
  6769. tempIndex = gun_index;
  6770. }
  6771. for (int index = 0; index < AC_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6776. }
  6777. }
  6778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6779. }
  6780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6781. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6784. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6785. }
  6786. //********************************(2)Energy.Active.Import.Register ************************************************/
  6787. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6788. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6789. (dataType == ReadingContext_Trigger))
  6790. {
  6791. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6793. {
  6794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6795. {
  6796. tempIndex = ((gun_index==2) ? 1: 0);
  6797. }
  6798. else
  6799. {
  6800. tempIndex = gun_index;
  6801. }
  6802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6803. {
  6804. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6805. {
  6806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6807. }
  6808. }
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6810. }
  6811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6812. {
  6813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6814. {
  6815. tempIndex = ((gun_index==2) ? 1: 0);
  6816. }
  6817. else
  6818. {
  6819. tempIndex = gun_index;
  6820. }
  6821. for (int index = 0; index < CCS_QUANTITY; index++)
  6822. {
  6823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6824. {
  6825. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6826. }
  6827. }
  6828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6829. }
  6830. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6831. {
  6832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6833. {
  6834. tempIndex = ((gun_index==2) ? 1: 0);
  6835. }
  6836. else
  6837. {
  6838. tempIndex = gun_index;
  6839. }
  6840. for (int index = 0; index < GB_QUANTITY; index++)
  6841. {
  6842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6843. {
  6844. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6845. }
  6846. }
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6848. }
  6849. else if(gunType[gun_index] == GUN_TYPE_DO)
  6850. {
  6851. tempIndex = gun_index;
  6852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6853. {
  6854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6855. {
  6856. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6857. }
  6858. }
  6859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6860. }
  6861. else
  6862. {
  6863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6864. {
  6865. tempIndex = 2;
  6866. }
  6867. else
  6868. {
  6869. tempIndex = gun_index;
  6870. }
  6871. for (int index = 0; index < AC_QUANTITY; index++)
  6872. {
  6873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6874. {
  6875. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6876. }
  6877. }
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6879. }
  6880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6885. }
  6886. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6887. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6888. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6889. (dataType == ReadingContext_Trigger))
  6890. {
  6891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6893. {
  6894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6895. {
  6896. tempIndex = ((gun_index==2) ? 1: 0);
  6897. }
  6898. else
  6899. {
  6900. tempIndex = gun_index;
  6901. }
  6902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6903. {
  6904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6905. {
  6906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6907. }
  6908. } // END OF FOR CHAdeMO_QUANTITY
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6910. }
  6911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6912. {
  6913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6914. {
  6915. tempIndex = ((gun_index==2) ? 1: 0);
  6916. }
  6917. else
  6918. {
  6919. tempIndex = gun_index;
  6920. }
  6921. for (int index = 0; index < CCS_QUANTITY; index++)
  6922. {
  6923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6924. {
  6925. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6926. }
  6927. } // END OF CCS_QUANTITY
  6928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6929. }
  6930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6931. {
  6932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6933. {
  6934. tempIndex = ((gun_index==2) ? 1: 0);
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. for (int index = 0; index < GB_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6943. {
  6944. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6945. }
  6946. } // END OF GB_QUANTITY
  6947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6948. }
  6949. else if(gunType[gun_index] == GUN_TYPE_DO)
  6950. {
  6951. tempIndex = gun_index;
  6952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6955. {
  6956. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6957. }
  6958. }
  6959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6960. }
  6961. else
  6962. {
  6963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6964. {
  6965. tempIndex = 2;
  6966. }
  6967. else
  6968. {
  6969. tempIndex = gun_index;
  6970. }
  6971. for (int index = 0; index < AC_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6974. {
  6975. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6976. }
  6977. }
  6978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6979. }
  6980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6985. }
  6986. //********************************(4)Power.Active.Import************************************************/
  6987. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6988. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6989. (dataType == ReadingContext_Trigger))
  6990. {
  6991. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6992. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6993. {
  6994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6995. {
  6996. tempIndex = ((gun_index==2) ? 1: 0);
  6997. }
  6998. else
  6999. {
  7000. tempIndex = gun_index;
  7001. }
  7002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7003. {
  7004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7005. {
  7006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7007. }
  7008. } // END OF FOR
  7009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7010. }
  7011. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7012. {
  7013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7014. {
  7015. tempIndex = ((gun_index==2) ? 1: 0);
  7016. }
  7017. else
  7018. {
  7019. tempIndex = gun_index;
  7020. }
  7021. for (int index = 0; index < CCS_QUANTITY; index++)
  7022. {
  7023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7024. {
  7025. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7026. }
  7027. }
  7028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7029. }
  7030. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7031. {
  7032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7033. {
  7034. tempIndex = ((gun_index==2) ? 1: 0);
  7035. }
  7036. else
  7037. {
  7038. tempIndex = gun_index;
  7039. }
  7040. for (int index = 0; index < GB_QUANTITY; index++)
  7041. {
  7042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7043. {
  7044. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7046. }
  7047. }
  7048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7049. }
  7050. else if(gunType[gun_index] == GUN_TYPE_DO)
  7051. {
  7052. tempIndex = gun_index;
  7053. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7054. {
  7055. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7056. {
  7057. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7058. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7059. }
  7060. }
  7061. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7062. }
  7063. else
  7064. {
  7065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7066. {
  7067. tempIndex = 2;
  7068. }
  7069. else
  7070. {
  7071. tempIndex = gun_index;
  7072. }
  7073. for (int index = 0; index < AC_QUANTITY; index++)
  7074. {
  7075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7076. {
  7077. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7078. }
  7079. }
  7080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7081. }
  7082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7086. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7087. }
  7088. //***********************************************(5)VOLTAGE L1******************************************************/
  7089. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7090. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7091. (dataType == ReadingContext_Trigger))
  7092. {
  7093. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7094. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7095. {
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7097. {
  7098. tempIndex = ((gun_index==2) ? 1: 0);
  7099. }
  7100. else
  7101. {
  7102. tempIndex = gun_index;
  7103. }
  7104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7107. {
  7108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7109. }
  7110. }
  7111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7112. }
  7113. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7114. {
  7115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7116. {
  7117. tempIndex = ((gun_index==2) ? 1: 0);
  7118. }
  7119. else
  7120. {
  7121. tempIndex = gun_index;
  7122. }
  7123. for (int index = 0; index < CCS_QUANTITY; index++)
  7124. {
  7125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7126. {
  7127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7128. }
  7129. }
  7130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7131. }
  7132. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7133. {
  7134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7135. {
  7136. tempIndex = ((gun_index==2) ? 1: 0);
  7137. }
  7138. else
  7139. {
  7140. tempIndex = gun_index;
  7141. }
  7142. for (int index = 0; index < GB_QUANTITY; index++)
  7143. {
  7144. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7145. {
  7146. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7147. }
  7148. }
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7150. }
  7151. else if(gunType[gun_index] == GUN_TYPE_DO)
  7152. {
  7153. tempIndex = gun_index;
  7154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7155. {
  7156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7157. {
  7158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7159. }
  7160. }
  7161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7162. }
  7163. else
  7164. {
  7165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7166. {
  7167. tempIndex = 2;
  7168. }
  7169. else
  7170. {
  7171. tempIndex = gun_index;
  7172. }
  7173. for (int index = 0; index < AC_QUANTITY; index++)
  7174. {
  7175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7176. {
  7177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7178. }
  7179. }
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7181. }
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7187. }
  7188. //***********************************************(6)SOC******************************************************/
  7189. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7190. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7191. (dataType == ReadingContext_Trigger))
  7192. {
  7193. 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))
  7194. {
  7195. //idx_sample=5;
  7196. //sampledValue = NULL;
  7197. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7198. {
  7199. tempIndex = ((gun_index==2) ? 1: 0);
  7200. }
  7201. else
  7202. {
  7203. tempIndex = gun_index;
  7204. }
  7205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7206. {
  7207. //tempIndex = ((gun_index==2) ? 1: 0);
  7208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7209. {
  7210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7211. {
  7212. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7213. }
  7214. }
  7215. }
  7216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7217. {
  7218. //tempIndex = ((gun_index==2) ? 1: 0);
  7219. for (int index = 0; index < CCS_QUANTITY; index++)
  7220. {
  7221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7222. {
  7223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7224. }
  7225. }
  7226. }
  7227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7228. {
  7229. //tempIndex = ((gun_index==2) ? 1: 0);
  7230. for (int index = 0; index < GB_QUANTITY; index++)
  7231. {
  7232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7233. {
  7234. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7235. }
  7236. }
  7237. }
  7238. else if(gunType[gun_index] == GUN_TYPE_DO)
  7239. {
  7240. //tempIndex = ((gun_index==2) ? 1: 0);
  7241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7244. {
  7245. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7246. }
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7255. }
  7256. }
  7257. //********************************(7)Current.Import L2************************************************/
  7258. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7259. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7260. (dataType == ReadingContext_Trigger))
  7261. {
  7262. // Only for AC 3 phase
  7263. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7266. {
  7267. tempIndex = 2;
  7268. }
  7269. else
  7270. {
  7271. tempIndex = gun_index;
  7272. }
  7273. for (int index = 0; index < AC_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7276. {
  7277. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7278. }
  7279. }
  7280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7281. }
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7287. }
  7288. //********************************(8)Current.Import L3************************************************/
  7289. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7290. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7291. (dataType == ReadingContext_Trigger))
  7292. {
  7293. // Only for AC 3 phase
  7294. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7295. {
  7296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7297. {
  7298. tempIndex = 2;
  7299. }
  7300. else
  7301. {
  7302. tempIndex = gun_index;
  7303. }
  7304. for (int index = 0; index < AC_QUANTITY; index++)
  7305. {
  7306. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7307. {
  7308. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7309. }
  7310. }
  7311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7312. }
  7313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7318. }
  7319. //***********************************************(9)VOLTAGE L2******************************************************/
  7320. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7321. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7322. (dataType == ReadingContext_Trigger))
  7323. {
  7324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7325. {
  7326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7327. {
  7328. tempIndex = 2;
  7329. }
  7330. else
  7331. {
  7332. tempIndex = gun_index;
  7333. }
  7334. for (int index = 0; index < AC_QUANTITY; index++)
  7335. {
  7336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7337. {
  7338. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7339. }
  7340. }
  7341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7342. }
  7343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7348. }
  7349. //***********************************************(10)VOLTAGE L3******************************************************/
  7350. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7351. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7352. (dataType == ReadingContext_Trigger))
  7353. {
  7354. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7355. {
  7356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7357. {
  7358. tempIndex = 2;
  7359. }
  7360. else
  7361. {
  7362. tempIndex = gun_index;
  7363. }
  7364. for (int index = 0; index < AC_QUANTITY; index++)
  7365. {
  7366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7367. {
  7368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7369. }
  7370. }
  7371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7372. }
  7373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7378. }
  7379. //***********************************************(11)Current.Offered******************************************************/
  7380. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7381. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7382. (dataType == ReadingContext_Trigger))
  7383. {
  7384. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7385. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7386. {
  7387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7388. {
  7389. tempIndex = ((gun_index==2) ? 1: 0);
  7390. }
  7391. else
  7392. {
  7393. tempIndex = gun_index;
  7394. }
  7395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7396. {
  7397. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7398. {
  7399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7400. }
  7401. } // END OF FOR CHAdeMO_QUANTITY
  7402. }
  7403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7404. {
  7405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7406. {
  7407. tempIndex = ((gun_index==2) ? 1: 0);
  7408. }
  7409. else
  7410. {
  7411. tempIndex = gun_index;
  7412. }
  7413. for (int index = 0; index < CCS_QUANTITY; index++)
  7414. {
  7415. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7416. {
  7417. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7418. }
  7419. } // END OF CCS_QUANTITY
  7420. }
  7421. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7422. {
  7423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7424. {
  7425. tempIndex = ((gun_index==2) ? 1: 0);
  7426. }
  7427. else
  7428. {
  7429. tempIndex = gun_index;
  7430. }
  7431. for (int index = 0; index < GB_QUANTITY; index++)
  7432. {
  7433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7434. {
  7435. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7436. }
  7437. } // END OF GB_QUANTITY
  7438. }
  7439. else if(gunType[gun_index] == GUN_TYPE_DO)
  7440. {
  7441. tempIndex = gun_index;
  7442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7443. {
  7444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7445. {
  7446. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7447. }
  7448. }
  7449. }
  7450. else
  7451. {
  7452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7453. {
  7454. tempIndex = 2;
  7455. }
  7456. else
  7457. {
  7458. tempIndex = gun_index;
  7459. }
  7460. for (int index = 0; index < AC_QUANTITY; index++)
  7461. {
  7462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7463. {
  7464. uint16_t currentOffer;
  7465. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7466. {
  7467. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7468. }
  7469. else
  7470. {
  7471. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7472. }
  7473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7474. }
  7475. }
  7476. }
  7477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7482. }
  7483. //***********************************************(12)Power.Offered******************************************************/
  7484. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7485. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7486. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7487. {
  7488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7490. {
  7491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7492. {
  7493. tempIndex = ((gun_index==2) ? 1: 0);
  7494. }
  7495. else
  7496. {
  7497. tempIndex = gun_index;
  7498. }
  7499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7500. {
  7501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7502. {
  7503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7504. }
  7505. } // END OF FOR CHAdeMO_QUANTITY
  7506. }
  7507. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7508. {
  7509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7510. {
  7511. tempIndex = ((gun_index==2) ? 1: 0);
  7512. }
  7513. else
  7514. {
  7515. tempIndex = gun_index;
  7516. }
  7517. for (int index = 0; index < CCS_QUANTITY; index++)
  7518. {
  7519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7520. {
  7521. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7522. }
  7523. } // END OF CCS_QUANTITY
  7524. }
  7525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7526. {
  7527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7528. {
  7529. tempIndex = ((gun_index==2) ? 1: 0);
  7530. }
  7531. else
  7532. {
  7533. tempIndex = gun_index;
  7534. }
  7535. for (int index = 0; index < GB_QUANTITY; index++)
  7536. {
  7537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7538. {
  7539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7540. }
  7541. } // END OF GB_QUANTITY
  7542. }
  7543. else if(gunType[gun_index] == GUN_TYPE_DO)
  7544. {
  7545. tempIndex = gun_index;
  7546. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7547. {
  7548. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7549. {
  7550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7551. }
  7552. }
  7553. }
  7554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7559. }
  7560. // Message create ====================================================================================================
  7561. if(TRUE)
  7562. {
  7563. json_object *MeterValueReq = json_object_new_object();
  7564. json_object *MeterValues = json_object_new_array();
  7565. json_object *sampledValues = json_object_new_array();
  7566. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7567. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7568. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7569. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7570. {
  7571. json_object *MeterValue = json_object_new_object();
  7572. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7573. {
  7574. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7575. {
  7576. json_object *sampledValue = json_object_new_object();
  7577. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7578. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7579. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7580. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7581. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7582. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7583. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7584. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7585. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7586. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7587. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7588. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7589. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7590. json_object_array_add(sampledValues, sampledValue);
  7591. }
  7592. }
  7593. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7594. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7595. json_object_array_add(MeterValues, MeterValue);
  7596. }
  7597. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7598. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7599. ,gun_index + 1
  7600. ,MESSAGE_TYPE_CALL
  7601. ,guid
  7602. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7603. json_object_put(MeterValueReq);
  7604. }
  7605. // Put request guid to hash map
  7606. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7607. 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*/)
  7608. {
  7609. result = PASS;
  7610. //DEBUG_INFO("MeterValues mapitem pass\n");
  7611. }
  7612. if((dataType != ReadingContext_Trigger) &&
  7613. (dataType != ReadingContext_Sample_Clock) &&
  7614. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7615. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7616. else
  7617. {
  7618. if(FirstHeartBeat)
  7619. LWS_Send(queuedata +2);
  7620. }
  7621. return result;
  7622. }
  7623. int sendLogStatusNotificationRequest(char *status)
  7624. {
  7625. mtrace();
  7626. int result = PASS;
  7627. char message[4096]={0};
  7628. char guid[37]={0};
  7629. char tempdata[128]={0};
  7630. json_object *LogStatusNotification = json_object_new_object();
  7631. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7632. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7633. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7634. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7635. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7636. random_uuid(guid);
  7637. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7638. json_object_put(LogStatusNotification);
  7639. LWS_Send(message);
  7640. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7641. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7642. {
  7643. result = PASS;
  7644. }
  7645. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7646. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7647. return result;
  7648. }
  7649. int sendSecurityEventNotificationRequest()
  7650. {
  7651. mtrace();
  7652. int result = PASS;
  7653. char message[4096]={0};
  7654. char guid[37]={0};
  7655. char tempdata[128]={0};
  7656. json_object *SecurityEventNotification = json_object_new_object();
  7657. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7658. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7659. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7660. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7661. random_uuid(guid);
  7662. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7663. json_object_put(SecurityEventNotification);
  7664. LWS_Send(message);
  7665. sprintf(tempdata, "SecurityEventNotification,0");
  7666. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7667. {
  7668. result = PASS;
  7669. }
  7670. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7671. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7672. return result;
  7673. }
  7674. int sendSignCertificateRequest()
  7675. {
  7676. mtrace();
  7677. int result = PASS;
  7678. char message[4096]={0};
  7679. char guid[37]={0};
  7680. char tempdata[128]={0};
  7681. json_object *SignCertificate = json_object_new_object();
  7682. DEBUG_INFO("sendSignCertificateRequest...\n");
  7683. // Read csr file content
  7684. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7685. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7686. char *line = NULL;
  7687. size_t len = 0;
  7688. while(getline(&line, &len, fp) != -1)
  7689. {
  7690. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7691. {
  7692. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7693. }
  7694. }
  7695. fclose(fp);
  7696. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7697. random_uuid(guid);
  7698. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7699. json_object_put(SignCertificate);
  7700. LWS_Send(message);
  7701. sprintf(tempdata, "SignCertificate,0");
  7702. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7703. {
  7704. result = PASS;
  7705. }
  7706. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7707. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7708. return result;
  7709. }
  7710. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7711. {
  7712. mtrace();
  7713. int result = PASS;
  7714. char message[110]={0};
  7715. char guid[37]={0};
  7716. char tempdata[65]={0};
  7717. json_object *FirmwareStatusNotification = json_object_new_object();
  7718. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7719. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7720. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7721. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7722. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7723. random_uuid(guid);
  7724. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7725. json_object_put(FirmwareStatusNotification);
  7726. LWS_Send(message);
  7727. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7728. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7729. {
  7730. result = PASS;
  7731. }
  7732. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7733. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7734. return result;
  7735. }
  7736. //==========================================
  7737. // send confirm routine
  7738. //==========================================
  7739. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7740. {
  7741. mtrace();
  7742. int result = FAIL;
  7743. char message[100]={0};
  7744. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7745. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7746. LWS_Send(message);
  7747. result = TRUE;
  7748. return result;
  7749. }
  7750. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7751. {
  7752. mtrace();
  7753. int result = FAIL;
  7754. char message[100]={0};
  7755. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7756. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7757. LWS_Send(message);
  7758. result = TRUE;
  7759. return result;
  7760. }
  7761. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7762. {
  7763. mtrace();
  7764. int result = FAIL;
  7765. char message[100]={0};
  7766. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7767. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7768. LWS_Send(message);
  7769. result = TRUE;
  7770. return result;
  7771. }
  7772. int sendClearCacheConfirmation(char *uuid,char *payload)
  7773. {
  7774. mtrace();
  7775. int result = FAIL;
  7776. char message[500]={0};
  7777. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7779. LWS_Send(message);
  7780. return result;
  7781. }
  7782. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7783. {
  7784. mtrace();
  7785. int result = FAIL;
  7786. char message[500]={0};
  7787. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7788. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7789. LWS_Send(message);
  7790. return result;
  7791. }
  7792. int sendDataTransferConfirmation(char *uuid,char *payload)
  7793. {
  7794. mtrace();
  7795. char statusStr[20]={0};
  7796. char dataStr[10]={0};
  7797. char sstr[20]={0};
  7798. int c = 0;
  7799. char *loc;
  7800. int result = FAIL;
  7801. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7802. /**********************status**************************/
  7803. loc = strstr(payload, "status");
  7804. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7805. c = 0;
  7806. while (loc[3+strlen("status")+c] != '\"')
  7807. {
  7808. sstr[c] = loc[3+strlen("status")+c];
  7809. c++;
  7810. }
  7811. sstr[c] = '\0';
  7812. strcpy(statusStr, sstr);
  7813. /**********************data**************************/
  7814. loc = strstr(payload, "data");
  7815. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7816. c = 0;
  7817. while (loc[3+strlen("data")+c] != '\"')
  7818. {
  7819. sstr[c] = loc[3+strlen("data")+c];
  7820. c++;
  7821. }
  7822. sstr[c] = '\0';
  7823. strcpy(dataStr, sstr);
  7824. return result;
  7825. }
  7826. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7827. {
  7828. mtrace();
  7829. int result = FAIL;
  7830. char message[1000]={0};
  7831. int CompositeScheduleIndex = 0;
  7832. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7833. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7834. if(nPeriod == 0)
  7835. {
  7836. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7837. {
  7838. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7839. ,MESSAGE_TYPE_CALLRESULT
  7840. ,uuid
  7841. ,payload
  7842. ,connectorIdInt);
  7843. }
  7844. else
  7845. {
  7846. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7847. ,MESSAGE_TYPE_CALLRESULT
  7848. ,uuid
  7849. ,payload
  7850. ,connectorIdInt
  7851. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7852. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7853. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7854. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7855. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7856. }
  7857. }
  7858. else
  7859. {
  7860. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7861. ,MESSAGE_TYPE_CALLRESULT
  7862. ,uuid
  7863. ,payload
  7864. ,connectorIdInt
  7865. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7866. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7867. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7868. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7869. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7870. {
  7871. if (idx_sample == 0)
  7872. {
  7873. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7874. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7875. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7876. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7877. }
  7878. else
  7879. {
  7880. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7881. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7882. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7883. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7884. }
  7885. }
  7886. sprintf(message + strlen(message), "]}}]");
  7887. }
  7888. LWS_Send(message);
  7889. result = TRUE;
  7890. return result;
  7891. }
  7892. int sendGetConfigurationConfirmation(char *uuid)
  7893. {
  7894. mtrace();
  7895. int result = FAIL;
  7896. int MaxKeySupported = 0;
  7897. int sentConfigurationNumber= 0;
  7898. int sentunConfigurationNumber= 0;
  7899. char message[1024*10]={0};
  7900. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7901. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7902. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7903. ,MESSAGE_TYPE_CALLRESULT
  7904. ,uuid );
  7905. //configuration key
  7906. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7907. {
  7908. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7909. {
  7910. if (sentConfigurationNumber == 0)
  7911. {
  7912. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7913. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7914. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7915. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7916. }
  7917. else
  7918. {
  7919. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7920. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7921. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7922. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7923. }
  7924. sentConfigurationNumber = sentConfigurationNumber + 1;
  7925. }
  7926. }
  7927. sprintf(message + strlen(message), "]");
  7928. if(UnknownKeynum != 0)
  7929. {
  7930. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7931. //unkown key
  7932. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7933. {
  7934. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7935. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7936. if(sentunConfigurationNumber == 0)
  7937. {
  7938. sprintf(message + strlen(message), "\"%s\""
  7939. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7940. }
  7941. else
  7942. {
  7943. sprintf(message + strlen(message), ",\"%s\""
  7944. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7945. }
  7946. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7947. }
  7948. sprintf(message + strlen(message), "]");
  7949. }
  7950. sprintf(message + strlen(message), "}]");
  7951. LWS_Send(message);
  7952. return result;
  7953. }
  7954. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7955. {
  7956. mtrace();
  7957. int result = FAIL;
  7958. char message[400]={0};
  7959. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7960. if(strcmp(payload,"")==0)
  7961. {
  7962. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7963. }
  7964. else
  7965. {
  7966. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7967. }
  7968. LWS_Send(message);
  7969. result = TRUE;
  7970. return result;
  7971. }
  7972. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7973. {
  7974. mtrace();
  7975. int result = FAIL;
  7976. char message[80]={0};
  7977. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7978. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7979. LWS_Send(message);
  7980. result = TRUE;
  7981. return result;
  7982. }
  7983. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7984. {
  7985. mtrace();
  7986. int result = FAIL;
  7987. char message[80]={0};
  7988. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7989. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7990. LWS_Send(message);
  7991. result = TRUE;
  7992. return result;
  7993. }
  7994. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7995. {
  7996. mtrace();
  7997. int result = FAIL;
  7998. char message[80]={0};
  7999. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8000. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8001. LWS_Send(message);
  8002. result = TRUE;
  8003. return result;
  8004. }
  8005. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8006. {
  8007. mtrace();
  8008. int result = FAIL;
  8009. char message[80]={0};
  8010. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8011. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8013. LWS_Send(message);
  8014. result = TRUE;
  8015. return result;
  8016. }
  8017. int sendResetConfirmation(char *uuid,char *payload)
  8018. {
  8019. mtrace();
  8020. int result = FAIL;
  8021. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8022. char message[80]={0};
  8023. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8025. LWS_Send(message);
  8026. result = TRUE;
  8027. return result;
  8028. }
  8029. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8030. {
  8031. mtrace();
  8032. int result = FAIL;
  8033. char message[500]={0};
  8034. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8035. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8036. LWS_Send(message);
  8037. result = TRUE;
  8038. return result;
  8039. }
  8040. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8041. {
  8042. mtrace();
  8043. int result = FAIL;
  8044. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8045. char message[80]={0};
  8046. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8047. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8048. LWS_Send(message);
  8049. result = TRUE;
  8050. return result;
  8051. }
  8052. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8053. {
  8054. mtrace();
  8055. int result = FAIL;
  8056. char message[80]={0};
  8057. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8058. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8059. LWS_Send(message);
  8060. result = TRUE;
  8061. return result;
  8062. }
  8063. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8064. {
  8065. mtrace();
  8066. int result = FAIL;
  8067. char message[80]={0};
  8068. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8069. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8070. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8071. LWS_Send(message);
  8072. result = TRUE;
  8073. return result;
  8074. }
  8075. int sendUpdateFirmwareConfirmation(char *uuid)
  8076. {
  8077. mtrace();
  8078. int result = FAIL;
  8079. char message[60]={0};
  8080. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8081. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8082. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8083. LWS_Send(message);
  8084. result = TRUE;
  8085. return result;
  8086. }
  8087. int sendCertificateSignedConfirmation(char *uuid)
  8088. {
  8089. mtrace();
  8090. int result = PASS;
  8091. char message[4096]={0};
  8092. json_object *CertificateSigned = json_object_new_object();
  8093. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8094. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8095. sprintf(message,"[%d,\"%s\",%s]"
  8096. ,MESSAGE_TYPE_CALLRESULT
  8097. ,uuid
  8098. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8099. json_object_put(CertificateSigned);
  8100. LWS_Send(message);
  8101. return result;
  8102. }
  8103. int sendDeleteCertificateConfirmation(char *uuid)
  8104. {
  8105. mtrace();
  8106. int result = PASS;
  8107. char message[4096]={0};
  8108. json_object *DeleteCertificate = json_object_new_object();
  8109. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8110. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8111. sprintf(message,"[%d,\"%s\",%s]"
  8112. ,MESSAGE_TYPE_CALLRESULT
  8113. ,uuid
  8114. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8115. json_object_put(DeleteCertificate);
  8116. LWS_Send(message);
  8117. return result;
  8118. }
  8119. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8120. {
  8121. mtrace();
  8122. int result = PASS;
  8123. char message[4096]={0};
  8124. json_object *ExtendedTriggerMessage = json_object_new_object();
  8125. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8126. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8127. sprintf(message,"[%d,\"%s\",%s]"
  8128. ,MESSAGE_TYPE_CALLRESULT
  8129. ,uuid
  8130. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8131. json_object_put(ExtendedTriggerMessage);
  8132. LWS_Send(message);
  8133. return result;
  8134. }
  8135. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8136. {
  8137. mtrace();
  8138. int result = PASS;
  8139. char message[4096]={0};
  8140. json_object *GetInstalledCertificateIds = json_object_new_object();
  8141. json_object *certificateHashDataDatas = json_object_new_array();
  8142. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8143. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8144. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8145. {
  8146. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8147. {
  8148. json_object *certificateHashData = json_object_new_object();
  8149. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8150. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8151. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8152. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8153. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8154. }
  8155. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8156. }
  8157. else
  8158. {
  8159. json_object_put(certificateHashDataDatas);
  8160. }
  8161. sprintf(message,"[%d,\"%s\",%s]"
  8162. ,MESSAGE_TYPE_CALLRESULT
  8163. ,uuid
  8164. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8165. json_object_put(GetInstalledCertificateIds);
  8166. LWS_Send(message);
  8167. return result;
  8168. }
  8169. int sendGetLogConfirmation(char *uuid)
  8170. {
  8171. mtrace();
  8172. int result = PASS;
  8173. char message[4096]={0};
  8174. json_object *GetLog = json_object_new_object();
  8175. DEBUG_INFO("sendGetLogConfirmation...\n");
  8176. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8177. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8178. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8179. sprintf(message,"[%d,\"%s\",%s]"
  8180. ,MESSAGE_TYPE_CALLRESULT
  8181. ,uuid
  8182. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8183. json_object_put(GetLog);
  8184. LWS_Send(message);
  8185. return result;
  8186. }
  8187. int sendInstallCertificateConfirmation(char *uuid)
  8188. {
  8189. mtrace();
  8190. int result = PASS;
  8191. char message[4096]={0};
  8192. json_object *InstallCertificate = json_object_new_object();
  8193. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8194. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8195. sprintf(message,"[%d,\"%s\",%s]"
  8196. ,MESSAGE_TYPE_CALLRESULT
  8197. ,uuid
  8198. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8199. json_object_put(InstallCertificate);
  8200. LWS_Send(message);
  8201. return result;
  8202. }
  8203. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8204. {
  8205. mtrace();
  8206. int result = PASS;
  8207. char message[4096]={0};
  8208. json_object *SignedUpdateFirmware = json_object_new_object();
  8209. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8210. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8211. sprintf(message,"[%d,\"%s\",%s]"
  8212. ,MESSAGE_TYPE_CALLRESULT
  8213. ,uuid
  8214. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8215. json_object_put(SignedUpdateFirmware);
  8216. LWS_Send(message);
  8217. return result;
  8218. }
  8219. int sendUnknownConfirmation(char *uuid)
  8220. {
  8221. mtrace();
  8222. int result = PASS;
  8223. char message[256]={0};
  8224. DEBUG_INFO("sendUnknownConfirmation...\n");
  8225. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8226. LWS_Send(message);
  8227. return result;
  8228. }
  8229. //==========================================
  8230. // Handle server request routine Start
  8231. //==========================================
  8232. int handleCancelReservationRequest(char *uuid, char *payload)
  8233. {
  8234. mtrace();
  8235. int result = FAIL;
  8236. int gunNO = 0;
  8237. int reservationIdInt = -1;
  8238. char comfirmstr[20];
  8239. DEBUG_INFO("handleCancelReservationRequest...\n");
  8240. json_object *CancelReservation;
  8241. CancelReservation = json_tokener_parse(payload);
  8242. if(!is_error(CancelReservation))
  8243. {
  8244. // Required data
  8245. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8246. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8247. }
  8248. json_object_put(CancelReservation);
  8249. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8250. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8252. if(reservationIdInt != -1)
  8253. {
  8254. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8255. //check Transaction active
  8256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8258. {
  8259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8260. {
  8261. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8262. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8263. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8264. {
  8265. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8266. }
  8267. else
  8268. {
  8269. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8270. }
  8271. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8272. goto end;
  8273. }
  8274. }
  8275. for (int index = 0; index < CCS_QUANTITY; index++)
  8276. {
  8277. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8278. {
  8279. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8280. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8281. if(gunType[2] == GUN_TYPE_CCS)
  8282. {
  8283. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8284. }
  8285. else
  8286. {
  8287. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8288. }
  8289. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8290. goto end;
  8291. }
  8292. }
  8293. for (int index = 0; index < GB_QUANTITY; index++)
  8294. {
  8295. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8296. {
  8297. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8298. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8299. if(gunType[2] == GUN_TYPE_GBT)
  8300. {
  8301. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8302. }
  8303. else
  8304. {
  8305. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8306. }
  8307. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8308. goto end;
  8309. }
  8310. }
  8311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8312. {
  8313. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8314. {
  8315. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8316. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8317. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8318. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8319. goto end;
  8320. }
  8321. }
  8322. for (int index = 0; index < AC_QUANTITY; index++)
  8323. {
  8324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8325. {
  8326. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8327. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8329. {
  8330. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8331. }
  8332. else
  8333. {
  8334. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8335. }
  8336. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8337. goto end;
  8338. }
  8339. }
  8340. }
  8341. //The reservationId does NOT match the reservationId
  8342. sendCancelReservationConfirmation(uuid, comfirmstr);
  8343. end:
  8344. // Fill in ocpp packet uuid
  8345. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8346. return result;
  8347. }
  8348. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8349. {
  8350. mtrace();
  8351. int result = FAIL;
  8352. int gunIndex = -1;
  8353. char typeStr[16]={0};
  8354. char comfirmstr[20];
  8355. int specificId = FALSE;
  8356. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8357. json_object *ChangeAvailability;
  8358. ChangeAvailability = json_tokener_parse(payload);
  8359. if(!is_error(ChangeAvailability))
  8360. {
  8361. // Required data
  8362. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8363. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8364. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8365. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8366. }
  8367. json_object_put(ChangeAvailability);
  8368. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8369. {
  8370. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8371. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8372. }
  8373. else if(gunIndex == 0)
  8374. {
  8375. for(int i=0; i < gunTotalNumber; i++)
  8376. {
  8377. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8378. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8379. }
  8380. }
  8381. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8382. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8383. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8384. {
  8385. specificId = TRUE;
  8386. }
  8387. if(specificId == FALSE)
  8388. goto end;
  8389. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8390. {
  8391. //----------------------gunIndex is 0 ------------------------------------------------//
  8392. if(gunIndex == 0)
  8393. {
  8394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8395. {
  8396. for(int i=0; i < gunTotalNumber; i++)
  8397. {
  8398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8399. {
  8400. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8401. {
  8402. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8403. {
  8404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8405. goto end;
  8406. }
  8407. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8412. {
  8413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8414. goto end;
  8415. }
  8416. }
  8417. }//END FOR CHAdeMO_QUANTITY
  8418. for (int index = 0; index < CCS_QUANTITY; index++)
  8419. {
  8420. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8421. {
  8422. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8423. {
  8424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8425. goto end;
  8426. }
  8427. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8428. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8431. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8432. {
  8433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8434. goto end;
  8435. }
  8436. }
  8437. }//END FOR CCS_QUANTITY
  8438. for (int index = 0; index < GB_QUANTITY; index++)
  8439. {
  8440. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8441. {
  8442. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8443. {
  8444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8445. goto end;
  8446. }
  8447. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8448. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8450. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8451. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8452. {
  8453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8454. goto end;
  8455. }
  8456. }
  8457. }// END FOR GB_QUANTITY
  8458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8459. {
  8460. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8461. {
  8462. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8463. {
  8464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8465. goto end;
  8466. }
  8467. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8468. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8469. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8470. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8471. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8472. {
  8473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8474. goto end;
  8475. }
  8476. }
  8477. }// END FOR GENERAL_GUN_QUANTITY
  8478. for (int index = 0; index < AC_QUANTITY; index++)
  8479. {
  8480. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8481. {
  8482. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8483. {
  8484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8485. goto end;
  8486. }
  8487. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8488. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8489. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8490. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8492. {
  8493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8494. goto end;
  8495. }
  8496. }
  8497. }//END FOR AC_QUANTITY
  8498. }// END FOR gunTotalNumber
  8499. }
  8500. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8501. {
  8502. for(int i=0; i < gunTotalNumber; i++)
  8503. {
  8504. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8505. {
  8506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8507. goto end;
  8508. }
  8509. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8510. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8511. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8514. {
  8515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8516. goto end;
  8517. }
  8518. }
  8519. }
  8520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8521. goto end;
  8522. }
  8523. //----------------------gunIndex is not 0 ------------------------------------------------//
  8524. //check Transaction active
  8525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8526. {
  8527. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8528. {
  8529. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8530. {
  8531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8532. goto end;
  8533. }
  8534. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8535. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8536. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8537. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8538. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8539. {
  8540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8541. goto end;
  8542. }
  8543. else
  8544. {
  8545. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8547. goto end;
  8548. }
  8549. }
  8550. }//END FOR CHAdeMO_QUANTITY
  8551. for (int index = 0; index < CCS_QUANTITY; index++)
  8552. {
  8553. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8554. {
  8555. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8556. {
  8557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8558. goto end;
  8559. }
  8560. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8561. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8562. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8565. {
  8566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8567. goto end;
  8568. }
  8569. else
  8570. {
  8571. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8573. goto end;
  8574. }
  8575. }
  8576. }//END FOR CCS_QUANTITY
  8577. for (int index = 0; index < GB_QUANTITY; index++)
  8578. {
  8579. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8580. {
  8581. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8582. {
  8583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8584. goto end;
  8585. }
  8586. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8591. {
  8592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8593. goto end;
  8594. }
  8595. else
  8596. {
  8597. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8599. goto end;
  8600. }
  8601. }
  8602. }// END FOR GB_QUANTITY
  8603. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8604. {
  8605. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8606. {
  8607. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8608. {
  8609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8610. goto end;
  8611. }
  8612. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8613. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8614. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8615. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8617. {
  8618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8619. goto end;
  8620. }
  8621. else
  8622. {
  8623. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8625. goto end;
  8626. }
  8627. }
  8628. }// END FOR GENERAL_GUN_QUANTITY
  8629. for (int index = 0; index < AC_QUANTITY; index++)
  8630. {
  8631. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8632. {
  8633. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8634. {
  8635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8636. goto end;
  8637. }
  8638. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8640. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8641. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8642. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8643. {
  8644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8645. goto end;
  8646. }
  8647. else
  8648. {
  8649. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8651. goto end;
  8652. }
  8653. }
  8654. }//END FOR AC_QUANTITY
  8655. }//END FOR AvailabilityTypeStr[Inoperative]
  8656. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8657. {
  8658. //----------------------gunIndex is 0 ------------------------------------------------//
  8659. if(gunIndex == 0)
  8660. {
  8661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8662. {
  8663. for(int i=0; i < gunTotalNumber; i++)
  8664. {
  8665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8666. {
  8667. 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
  8668. {
  8669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8670. goto end;
  8671. }
  8672. }//END FOR CHAdeMO_QUANTITY
  8673. for (int index = 0; index < CCS_QUANTITY; index++)
  8674. {
  8675. 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
  8676. {
  8677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8678. goto end;
  8679. }
  8680. }//END FOR CCS_QUANTITY
  8681. for (int index = 0; index < GB_QUANTITY; index++)
  8682. {
  8683. 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
  8684. {
  8685. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8687. goto end;
  8688. }
  8689. }// END FOR GB_QUANTITY
  8690. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8691. {
  8692. 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
  8693. {
  8694. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8696. goto end;
  8697. }
  8698. }// END FOR GENERAL_GUN_QUANTITY
  8699. for (int index = 0; index < AC_QUANTITY; index++)
  8700. {
  8701. 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
  8702. {
  8703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8704. goto end;
  8705. }
  8706. }//END FOR CHAdeMO_QUANTITY
  8707. }// END FOR gunTotalNumber
  8708. }
  8709. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8710. {
  8711. for(int i=0; i < gunTotalNumber; i++)
  8712. {
  8713. for (int index = 0; index < AC_QUANTITY; index++)
  8714. {
  8715. 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
  8716. {
  8717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8718. goto end;
  8719. }
  8720. }//END FOR CHAdeMO_QUANTITY
  8721. } // END FOR gunTotalNumber
  8722. }
  8723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8724. goto end;
  8725. }
  8726. //----------------------gunIndex is not 0 ------------------------------------------------//
  8727. //check Transaction active
  8728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8729. {
  8730. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8731. {
  8732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8733. goto end;
  8734. }
  8735. }//END FOR CHAdeMO_QUANTITY
  8736. for (int index = 0; index < CCS_QUANTITY; index++)
  8737. {
  8738. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8739. {
  8740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8741. goto end;
  8742. }
  8743. }//END FOR CCS_QUANTITY
  8744. for (int index = 0; index < GB_QUANTITY; index++)
  8745. {
  8746. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8747. {
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8749. goto end;
  8750. }
  8751. }// END FOR GB_QUANTITY
  8752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8753. {
  8754. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8755. {
  8756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8757. goto end;
  8758. }
  8759. }// END FOR GENERAL_GUN_QUANTITY
  8760. for (int index = 0; index < AC_QUANTITY; index++)
  8761. {
  8762. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8763. {
  8764. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8765. goto end;
  8766. }
  8767. }//END FOR AC_QUANTITY
  8768. }//END FOR AvailabilityTypeStr[Operative]
  8769. end:
  8770. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8771. {
  8772. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8773. }
  8774. else
  8775. {
  8776. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8777. }
  8778. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8779. {
  8780. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8781. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8782. }
  8783. else if(gunIndex == 0)
  8784. {
  8785. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8786. {
  8787. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8788. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8789. }
  8790. }
  8791. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8792. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8793. return result;
  8794. }
  8795. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8796. {
  8797. mtrace();
  8798. int valueInvalid = NO;
  8799. int result = FAIL;
  8800. char keystr[40]={0};
  8801. char valuestr[501]={0}; //value should be limited in 500 bytes
  8802. char comfirmstr[20]={0};
  8803. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8804. json_object *ChangeConfiguration;
  8805. ChangeConfiguration = json_tokener_parse(payload);
  8806. if(!is_error(ChangeConfiguration))
  8807. {
  8808. // Required data
  8809. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8810. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8811. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8812. {
  8813. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8814. }
  8815. else
  8816. {
  8817. valueInvalid = YES;
  8818. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8819. }
  8820. }
  8821. json_object_put(ChangeConfiguration);
  8822. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8823. {
  8824. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8825. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8826. }
  8827. else
  8828. {
  8829. int status = setKeyValue(keystr, valuestr);
  8830. switch(status)
  8831. {
  8832. case ConfigurationStatus_Accepted:
  8833. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8834. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8835. StoreConfigurationTable();
  8836. break;
  8837. case RebootRequired:
  8838. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8839. StoreConfigurationTable();
  8840. break;
  8841. case NotSupported:
  8842. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8843. break;
  8844. case ConfigurationStatus_Rejected:
  8845. default:
  8846. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8847. break;
  8848. }
  8849. }
  8850. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8851. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8852. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8853. {
  8854. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8855. SetOcppConnStatus(FALSE);
  8856. }
  8857. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8858. {
  8859. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8860. }
  8861. return result;
  8862. }
  8863. int handleClearCacheRequest(char *uuid, char *payload)
  8864. {
  8865. mtrace();
  8866. int result = FAIL;
  8867. char comfirmstr[20];
  8868. char rmFileCmd[100]={0};
  8869. struct stat stats;
  8870. DEBUG_INFO("handleClearCacheRequest...\n");
  8871. stat("/Storage/OCPP", &stats);
  8872. // Check for directory existence
  8873. if (S_ISDIR(stats.st_mode) == 1)
  8874. {}
  8875. else
  8876. {
  8877. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8878. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8879. system(rmFileCmd);
  8880. }
  8881. if(OCPP_cleanLocalCache())
  8882. {
  8883. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8884. }
  8885. else
  8886. {
  8887. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8888. }
  8889. sendClearCacheConfirmation(uuid, comfirmstr);
  8890. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8891. return result;
  8892. }
  8893. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8894. {
  8895. mtrace();
  8896. int result = FAIL;
  8897. int resultRename;
  8898. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8899. char chargingProfilePurposeStr[26]={0};
  8900. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8901. char tempchargingProfilePurposeStr[26]={0};
  8902. char str[100]={0};
  8903. char fname[200]={0};
  8904. char comfirmstr[20]={0};
  8905. char word[1600]={0};
  8906. int clearflag = FALSE;
  8907. int chargingProfileIdIsNULL = FALSE;
  8908. int connectorIsNULL = FALSE;
  8909. int chargingProfilePurposeIsNULL = FALSE;
  8910. int stackLevelIsNULL = FALSE;
  8911. //int GotoEnd = FALSE;
  8912. FILE *fptr1, *fptr2;
  8913. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8914. int n_chargingProfile=0;
  8915. int isEmptyFile = FALSE;
  8916. char sLineWord[1600]={0};
  8917. char chargingProfiles[10][100]={0};
  8918. int ChargeProfileCount = 0;
  8919. int ch;
  8920. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8921. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8922. json_object *ClearChargingProfile;
  8923. ClearChargingProfile = json_tokener_parse(payload);
  8924. if(!is_error(ClearChargingProfile))
  8925. {
  8926. // Optional data
  8927. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8928. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8929. else
  8930. chargingProfileIdIsNULL = TRUE;
  8931. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8932. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8933. else
  8934. connectorIsNULL = TRUE;
  8935. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8936. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8937. else
  8938. chargingProfilePurposeIsNULL = TRUE;
  8939. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8940. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8941. else
  8942. stackLevelIsNULL = TRUE;
  8943. }
  8944. json_object_put(ClearChargingProfile);
  8945. if(connectorIsNULL == FALSE)
  8946. {
  8947. switch(connectorIdInt)
  8948. {
  8949. case 0:
  8950. if(chargingProfilePurposeIsNULL == TRUE)
  8951. {
  8952. int l = 0;
  8953. strcpy(fname, ChargePointMaxProfile_JSON);
  8954. if((access(fname,F_OK))!=-1)
  8955. {
  8956. strcpy(chargingProfiles[l], fname);
  8957. l = l + 1;
  8958. }
  8959. strcpy(fname, TxDefaultProfile_0_JSON);
  8960. if((access(fname,F_OK))!=-1)
  8961. {
  8962. strcpy(chargingProfiles[l], fname);
  8963. l = l + 1;
  8964. }
  8965. ChargeProfileCount = l;
  8966. }
  8967. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8968. {
  8969. strcpy(fname, ChargePointMaxProfile_JSON);
  8970. if((access(fname,F_OK))!=-1)
  8971. {
  8972. strcpy(chargingProfiles[0], fname);
  8973. ChargeProfileCount = 1;
  8974. }
  8975. }
  8976. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8977. {
  8978. strcpy(fname, TxDefaultProfile_0_JSON);
  8979. if((access(fname,F_OK))!=-1)
  8980. {
  8981. strcpy(chargingProfiles[0], fname);
  8982. ChargeProfileCount = 1;
  8983. }
  8984. }
  8985. break;
  8986. default:
  8987. if(chargingProfilePurposeIsNULL == TRUE)
  8988. {
  8989. int m = 0;
  8990. memset(fname, 0, ARRAY_SIZE(fname));
  8991. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8992. if((access(fname,F_OK))!=-1)
  8993. {
  8994. strcpy(chargingProfiles[m], fname);
  8995. m = m + 1;
  8996. }
  8997. memset(fname, 0, ARRAY_SIZE(fname));
  8998. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8999. if((access(fname,F_OK))!=-1)
  9000. {
  9001. strcpy(chargingProfiles[m], fname);
  9002. m = m + 1;
  9003. }
  9004. ChargeProfileCount = m;
  9005. }
  9006. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9007. {
  9008. //strcpy(fname, TxDefaultProfile_1_JSON);
  9009. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9010. if((access(fname,F_OK))!=-1)
  9011. {
  9012. strcpy(chargingProfiles[0], fname);
  9013. ChargeProfileCount = 1;
  9014. }
  9015. }
  9016. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9017. {
  9018. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9019. if((access(fname,F_OK))!=-1)
  9020. {
  9021. strcpy(chargingProfiles[0], fname);
  9022. ChargeProfileCount = 1;
  9023. }
  9024. //strcpy(fname, TxProfile_1_JSON);
  9025. }
  9026. //strcpy(fname, ChargePointMaxProfile_JSON );
  9027. break;
  9028. }
  9029. }
  9030. else // Check all Charging Profiles
  9031. {
  9032. int i = 0;
  9033. char fnametemp[200]={0};
  9034. ChargeProfileCount = 0;
  9035. //Check ChargePointMaxProfile.json exit
  9036. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9037. {
  9038. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9039. i = i + 1;
  9040. }
  9041. //Check TxDefaultProfile_0.json exit
  9042. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9043. {
  9044. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9045. i = i + 1;
  9046. }
  9047. //Check TxDefaultProfile_%d.json
  9048. for(int j=1; j <= gunTotalNumber; j++)
  9049. {
  9050. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9051. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9052. if((access(fnametemp,F_OK))!=-1)
  9053. {
  9054. strcpy(chargingProfiles[i], fnametemp);
  9055. i = i + 1;
  9056. }
  9057. }
  9058. //Check TxProfile_%d.json
  9059. for(int j=1; j <= gunTotalNumber; j++)
  9060. {
  9061. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9062. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9063. if((access(fnametemp,F_OK))!=-1)
  9064. {
  9065. strcpy(chargingProfiles[i], fnametemp);
  9066. i = i + 1;
  9067. }
  9068. }
  9069. ChargeProfileCount = i;
  9070. }// End connectorIsNULL is TRUE
  9071. if(ChargeProfileCount == 0)
  9072. {
  9073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9074. goto end;
  9075. }
  9076. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9077. {
  9078. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9079. goto end;
  9080. }
  9081. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9082. {
  9083. memset(str, 0, ARRAY_SIZE(str));
  9084. // clear temp file
  9085. sprintf(str,"rm -f %s",temp);
  9086. system(str);
  9087. for(int k=0; k < ChargeProfileCount; k++)
  9088. {
  9089. memset(str, 0, ARRAY_SIZE(str));
  9090. //clear file in C
  9091. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9092. system(str);
  9093. }
  9094. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9095. goto end;
  9096. }
  9097. else if(connectorIsNULL == TRUE)
  9098. {
  9099. for(int k=0; k < ChargeProfileCount; k++)
  9100. {
  9101. fptr1 = fopen(chargingProfiles[k], "r");
  9102. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9103. //Check Charging Profile Count
  9104. while(fscanf(fptr1, "%s", word) != EOF)
  9105. {
  9106. //DEBUG_INFO("word=%s\n",word);
  9107. if(strstr(word, "chargingProfileId")!= NULL)
  9108. {
  9109. //DEBUG_INFO("test chargingProfileId \n");
  9110. n_chargingProfile = n_chargingProfile + 1;
  9111. //DEBUG_INFO("chargingProfileId Found\n");
  9112. }
  9113. }
  9114. rewind(fptr1);
  9115. //search Charging Profile Element
  9116. //int i= 0;
  9117. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9118. {
  9119. json_object *tmpProfilee;
  9120. tmpProfilee = json_tokener_parse(sLineWord);
  9121. if(!is_error(tmpProfilee))
  9122. {
  9123. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9124. {
  9125. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9126. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9127. }
  9128. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9129. {
  9130. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9131. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9132. }
  9133. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9134. {
  9135. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9136. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9137. }
  9138. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9139. {
  9140. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9141. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9142. }
  9143. }
  9144. json_object_put(tmpProfilee);
  9145. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9146. {
  9147. //------- not write to fptr2-------//
  9148. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9149. //clearflag = TRUE;
  9150. }
  9151. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9152. {
  9153. //------- not write to fptr2-------//
  9154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9155. }
  9156. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9157. {
  9158. //------- not write to fptr2-------//
  9159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9160. }
  9161. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9162. {
  9163. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9164. }
  9165. else
  9166. {
  9167. fprintf(fptr2, sLineWord);//writing data into file
  9168. }
  9169. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9170. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9171. if(clearflag == TRUE)
  9172. {
  9173. fclose(fptr1);
  9174. fclose(fptr2);
  9175. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9176. system(str);
  9177. // clear temp file
  9178. sprintf(str,"rm -f %s",temp);
  9179. system(str);
  9180. }
  9181. else
  9182. {
  9183. fclose(fptr1);
  9184. fclose(fptr2);
  9185. memset(str, 0, ARRAY_SIZE(str));
  9186. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9187. system(str);
  9188. resultRename = rename(temp, chargingProfiles[k]);
  9189. if(resultRename == 0)
  9190. {
  9191. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9192. }
  9193. else
  9194. {
  9195. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9196. }
  9197. if(comfirmstr[0]== 0)
  9198. {
  9199. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9200. }
  9201. //Check chargingProfile is empty file
  9202. /*------ Read the file ----------------*/
  9203. fptr1=fopen(chargingProfiles[k],"r");
  9204. ch=fgetc(fptr1);
  9205. rewind(fptr1);
  9206. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9207. if(ch!=EOF)
  9208. {
  9209. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9210. {
  9211. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9212. if(sLineWord[0]=='\0')
  9213. {
  9214. isEmptyFile = TRUE;
  9215. break;
  9216. }
  9217. else
  9218. {
  9219. isEmptyFile = FALSE;
  9220. break;
  9221. }
  9222. }
  9223. }
  9224. else
  9225. isEmptyFile = TRUE;
  9226. fclose(fptr1);
  9227. if(isEmptyFile == TRUE)
  9228. {
  9229. memset(str, 0, ARRAY_SIZE(str));
  9230. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9231. system(str);
  9232. }
  9233. }
  9234. }// End of while(int k=0; k < ChargePointCount; k++)
  9235. }
  9236. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9237. {
  9238. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9239. for(int k=0; k < ChargeProfileCount; k++)
  9240. {
  9241. fptr1 = fopen(chargingProfiles[k], "r");
  9242. fptr2 = fopen(temp, "w+");
  9243. //Check Charging Profile Count
  9244. while(fscanf(fptr1, "%s", word) != EOF)
  9245. {
  9246. //DEBUG_INFO("word=%s\n",word);
  9247. if(strstr(word, "chargingProfileId")!= NULL)
  9248. {
  9249. n_chargingProfile = n_chargingProfile + 1;
  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((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9290. {
  9291. //------- not write to fptr2-------//
  9292. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9293. }
  9294. else if(stackLevelIsNULL == TRUE)
  9295. {
  9296. //Clear Whole File
  9297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9298. clearflag = TRUE;
  9299. break;
  9300. }
  9301. else
  9302. {
  9303. fprintf(fptr2, sLineWord);//writing data into file
  9304. }
  9305. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9306. }
  9307. if(clearflag == TRUE)
  9308. {
  9309. fclose(fptr1);
  9310. fclose(fptr2);
  9311. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9312. system(str);
  9313. // clear temp file
  9314. sprintf(str,"rm -f %s",temp);
  9315. system(str);
  9316. }
  9317. else
  9318. {
  9319. fclose(fptr1);
  9320. fclose(fptr2);
  9321. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9322. system(str);
  9323. resultRename = rename(temp, chargingProfiles[k]);
  9324. if(resultRename == 0)
  9325. {
  9326. DEBUG_INFO("File ChargingProfile renamed successfully");
  9327. }
  9328. else
  9329. {
  9330. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9331. }
  9332. if(comfirmstr[0]== 0)
  9333. {
  9334. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9335. }
  9336. //Check chargingProfile is empty file
  9337. /*------ Read the file ----------------*/
  9338. fptr1=fopen(chargingProfiles[k],"r");
  9339. ch=fgetc(fptr1);
  9340. rewind(fptr1);
  9341. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9342. if(ch!=EOF)
  9343. {
  9344. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9345. {
  9346. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9347. if(sLineWord[0]=='\0')
  9348. {
  9349. isEmptyFile = TRUE;
  9350. break;
  9351. }
  9352. else
  9353. {
  9354. isEmptyFile = FALSE;
  9355. break;
  9356. }
  9357. }
  9358. }
  9359. else
  9360. isEmptyFile = TRUE;
  9361. fclose(fptr1);
  9362. if(isEmptyFile == TRUE)
  9363. {
  9364. memset(str, 0, ARRAY_SIZE(str));
  9365. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9366. system(str);
  9367. }
  9368. /*------- End of reading ---------------*/
  9369. }
  9370. } // while(int k=0; k < ChargeProfileCount; k++)
  9371. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9372. end:
  9373. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9374. {
  9375. if(connectorIdInt == 0)
  9376. {
  9377. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9378. {
  9379. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9380. }
  9381. }
  9382. else
  9383. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9384. }
  9385. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9386. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9387. return result;
  9388. }
  9389. void createFirmwareVersionByDataTransfer(void)
  9390. {
  9391. json_object *FirmwareDataTransfer = json_object_new_object();
  9392. // AC & DC model
  9393. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9394. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9395. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9396. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9397. // DC model
  9398. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9399. {
  9400. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9401. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9402. (gunType[3] != GUN_TYPE_UNKNOWN))
  9403. {
  9404. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9405. }
  9406. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9407. {
  9408. // DS DM DW
  9409. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9410. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9411. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9412. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9413. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9414. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9415. }
  9416. else
  9417. {
  9418. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9419. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9420. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9421. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9422. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9423. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9424. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9425. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9426. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9427. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9428. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9429. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9430. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9431. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9432. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9433. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9434. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9435. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9436. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9437. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9438. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9439. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9440. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9441. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9442. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9443. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9444. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9445. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9446. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9447. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9448. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9449. }
  9450. }
  9451. // 4G model
  9452. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9453. {
  9454. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9455. }
  9456. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9457. json_object_put(FirmwareDataTransfer);
  9458. }
  9459. int handleDataTransferRequest(char *uuid, char *payload)
  9460. {
  9461. mtrace();
  9462. json_object *response = json_object_new_object();
  9463. int result = FAIL;
  9464. char tempvendorId[255]={0};
  9465. char tempmessageId[50]={0};
  9466. char tempdata[1024]={0};
  9467. char message[2048]={0};
  9468. DEBUG_INFO("handleDataTransferRequest...\n");
  9469. if((uuid != NULL) && (payload != NULL))
  9470. {
  9471. json_object *DataTransfer;
  9472. DataTransfer = json_tokener_parse(payload);
  9473. if(!is_error(DataTransfer))
  9474. {
  9475. // Required data
  9476. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9477. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9478. // Optional data
  9479. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9480. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9481. if(json_object_object_get(DataTransfer, "data") != NULL)
  9482. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9483. result = PASS;
  9484. }
  9485. json_object_put(DataTransfer);
  9486. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9487. {
  9488. // Send all moudle firmware version on EVSE
  9489. createFirmwareVersionByDataTransfer();
  9490. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9491. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9493. json_object_put(response);
  9494. }
  9495. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9496. {
  9497. system("/usr/bin/run_tmate_restart.sh &");
  9498. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9499. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9500. json_object_put(response);
  9501. }
  9502. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9503. {
  9504. json_object *data;
  9505. data = json_tokener_parse(tempdata);
  9506. if(!is_error(data))
  9507. {
  9508. 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))
  9509. {
  9510. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9511. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9512. if(json_object_object_get(data, "SOC") != NULL)
  9513. {
  9514. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9515. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9516. }
  9517. if(json_object_object_get(data, "Energy") != NULL)
  9518. {
  9519. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9520. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9521. }
  9522. if(json_object_object_get(data, "Duration") != NULL)
  9523. {
  9524. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9525. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9526. }
  9527. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9528. }
  9529. else
  9530. {
  9531. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9532. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9533. }
  9534. }
  9535. else
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9538. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9539. }
  9540. json_object_put(data);
  9541. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9542. json_object_put(response);
  9543. }
  9544. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9545. {
  9546. json_object *data;
  9547. data = json_tokener_parse(tempdata);
  9548. if(!is_error(data))
  9549. {
  9550. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9551. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9552. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9553. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9554. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9555. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9556. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9557. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9558. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9559. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9560. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9561. }
  9562. else
  9563. {
  9564. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9565. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9566. }
  9567. json_object_put(data);
  9568. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9569. json_object_put(response);
  9570. }
  9571. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9572. {
  9573. json_object *data;
  9574. data = json_tokener_parse(tempdata);
  9575. if(!is_error(data))
  9576. {
  9577. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9578. if(json_object_object_get(data, "idToken") != NULL)
  9579. {
  9580. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9581. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9582. }
  9583. if(json_object_object_get(data, "price") != NULL)
  9584. {
  9585. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9586. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9587. }
  9588. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9589. }
  9590. else
  9591. {
  9592. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9593. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9594. }
  9595. json_object_put(data);
  9596. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9597. json_object_put(response);
  9598. }
  9599. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9600. {
  9601. json_object *data;
  9602. data = json_tokener_parse(tempdata);
  9603. if(!is_error(data))
  9604. {
  9605. if(json_object_object_get(data, "txId") != NULL)
  9606. {
  9607. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9608. for(int idx = 0;idx<gunTotalNumber;idx++)
  9609. {
  9610. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9611. {
  9612. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9613. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9614. if(json_object_object_get(data, "description") != NULL)
  9615. {
  9616. // California pricing V1.0
  9617. DEBUG_INFO("California pricing V1.0\n");
  9618. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9619. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9620. }
  9621. else
  9622. {
  9623. // California pricing V1.1
  9624. DEBUG_INFO("California pricing V1.1\n");
  9625. if(json_object_object_get(data, "timestamp") != NULL)
  9626. {
  9627. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9628. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9629. }
  9630. if(json_object_object_get(data, "meterValue") != NULL)
  9631. {
  9632. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9633. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9634. }
  9635. if(json_object_object_get(data, "cost") != NULL)
  9636. {
  9637. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9638. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9639. }
  9640. if(json_object_object_get(data, "state") != NULL)
  9641. {
  9642. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9643. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9644. }
  9645. if(json_object_object_get(data, "chargingPrice") != NULL)
  9646. {
  9647. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9648. {
  9649. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9650. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9651. }
  9652. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9653. {
  9654. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9655. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9656. }
  9657. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9658. {
  9659. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9660. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9661. }
  9662. }
  9663. if(json_object_object_get(data, "idlePrice") != NULL)
  9664. {
  9665. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9666. {
  9667. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9668. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9669. }
  9670. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9671. {
  9672. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9673. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9674. }
  9675. }
  9676. if(json_object_object_get(data, "nextPeriod") != NULL)
  9677. {
  9678. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9679. {
  9680. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9681. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9682. }
  9683. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9684. {
  9685. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9686. {
  9687. 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")));
  9688. 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"));
  9689. }
  9690. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9691. {
  9692. 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")));
  9693. 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"));
  9694. }
  9695. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9696. {
  9697. 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")));
  9698. 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"));
  9699. }
  9700. }
  9701. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9702. {
  9703. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9704. {
  9705. 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")));
  9706. 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"));
  9707. }
  9708. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9709. {
  9710. 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")));
  9711. 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"));
  9712. }
  9713. }
  9714. }
  9715. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9716. {
  9717. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9718. {
  9719. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9720. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9721. }
  9722. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9723. {
  9724. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9725. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9726. }
  9727. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9728. {
  9729. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9730. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9731. }
  9732. }
  9733. }
  9734. }
  9735. }
  9736. }
  9737. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9738. }
  9739. else
  9740. {
  9741. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9742. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9743. }
  9744. json_object_put(data);
  9745. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9746. json_object_put(response);
  9747. }
  9748. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9749. {
  9750. json_object *data;
  9751. data = json_tokener_parse(tempdata);
  9752. if(!is_error(data))
  9753. {
  9754. if(json_object_object_get(data, "txId") != NULL)
  9755. {
  9756. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9757. for(int idx = 0;idx<gunTotalNumber;idx++)
  9758. {
  9759. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9760. {
  9761. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9762. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9763. if(json_object_object_get(data, "description") != NULL)
  9764. {
  9765. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9766. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9767. }
  9768. }
  9769. }
  9770. }
  9771. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9772. }
  9773. else
  9774. {
  9775. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9776. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9777. }
  9778. json_object_put(data);
  9779. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9780. json_object_put(response);
  9781. }
  9782. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9783. {
  9784. json_object *data;
  9785. data = json_tokener_parse(tempdata);
  9786. if(!is_error(data))
  9787. {
  9788. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9789. if(json_object_object_get(data, "Content_Type") != NULL)
  9790. {
  9791. 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))
  9792. {
  9793. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9794. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9795. {
  9796. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9797. }
  9798. }
  9799. else
  9800. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9801. }
  9802. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9803. }
  9804. else
  9805. {
  9806. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9807. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9808. }
  9809. json_object_put(data);
  9810. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9811. json_object_put(response);
  9812. }
  9813. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9814. {
  9815. json_object *data;
  9816. data = json_tokener_parse(tempdata);
  9817. if(!is_error(data))
  9818. {
  9819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9820. if(json_object_object_get(data, "ConnectorId") != NULL)
  9821. {
  9822. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9823. }
  9824. if(json_object_object_get(data, "SerialNo") != NULL)
  9825. {
  9826. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9827. }
  9828. if(json_object_object_get(data, "Page_Index") != NULL)
  9829. {
  9830. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9831. }
  9832. if(json_object_object_get(data, "Duration") != NULL)
  9833. {
  9834. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9835. }
  9836. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9842. }
  9843. json_object_put(data);
  9844. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9845. json_object_put(response);
  9846. }
  9847. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9848. {
  9849. json_object *data;
  9850. data = json_tokener_parse(tempdata);
  9851. if(!is_error(data))
  9852. {
  9853. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9854. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9855. {
  9856. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9857. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9858. else
  9859. {
  9860. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9861. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9862. }
  9863. }
  9864. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9865. {
  9866. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9867. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9868. else
  9869. {
  9870. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9871. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9872. }
  9873. }
  9874. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9875. {
  9876. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9877. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  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("Configuration content something wrong."));
  9882. }
  9883. }
  9884. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9885. {
  9886. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9887. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9888. else
  9889. {
  9890. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9891. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9892. }
  9893. }
  9894. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9895. {
  9896. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9897. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9898. else
  9899. {
  9900. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9901. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9902. }
  9903. }
  9904. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9905. {
  9906. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9907. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9908. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9909. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9910. else
  9911. {
  9912. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9913. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9914. }
  9915. }
  9916. if(json_object_object_get(data, "isAuthentication") != NULL)
  9917. {
  9918. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9919. {
  9920. case 0:
  9921. case 1:
  9922. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9923. break;
  9924. default:
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9927. break;
  9928. }
  9929. }
  9930. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9931. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9932. }
  9933. else
  9934. {
  9935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9936. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9937. }
  9938. json_object_put(data);
  9939. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9940. json_object_put(response);
  9941. }
  9942. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9943. {
  9944. json_object *data;
  9945. data = json_tokener_parse(tempdata);
  9946. if(!is_error(data))
  9947. {
  9948. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9949. {
  9950. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9951. {
  9952. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9953. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9954. }
  9955. else
  9956. {
  9957. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9958. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9959. }
  9960. }
  9961. else
  9962. {
  9963. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9964. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9965. }
  9966. }
  9967. else
  9968. {
  9969. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9970. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9971. }
  9972. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9973. json_object_put(response);
  9974. }
  9975. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9976. {
  9977. json_object *data;
  9978. data = json_tokener_parse(tempdata);
  9979. if(!is_error(data))
  9980. {
  9981. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9982. if(json_object_object_get(data, "stationName") != NULL)
  9983. {
  9984. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9985. }
  9986. else
  9987. {
  9988. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9989. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9990. }
  9991. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9992. {
  9993. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9994. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9995. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9996. }
  9997. }
  9998. else
  9999. {
  10000. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10001. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10002. }
  10003. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10004. json_object_put(response);
  10005. }
  10006. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10007. {
  10008. json_object *data;
  10009. data = json_tokener_parse(tempdata);
  10010. if(!is_error(data))
  10011. {
  10012. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10013. if(json_object_object_get(data, "weatherId") != NULL)
  10014. {
  10015. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10016. }
  10017. else
  10018. {
  10019. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10020. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10021. }
  10022. if(json_object_object_get(data, "Temperature") != NULL)
  10023. {
  10024. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10025. }
  10026. else
  10027. {
  10028. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10029. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10030. }
  10031. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10032. {
  10033. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10034. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10035. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10036. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10037. );
  10038. }
  10039. }
  10040. else
  10041. {
  10042. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10043. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10044. }
  10045. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10046. json_object_put(response);
  10047. }
  10048. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10049. {
  10050. json_object *data;
  10051. data = json_tokener_parse(tempdata);
  10052. if(!is_error(data))
  10053. {
  10054. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10055. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10056. {
  10057. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10058. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10059. }
  10060. else
  10061. {
  10062. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10063. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10064. }
  10065. }
  10066. else
  10067. {
  10068. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10069. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10070. }
  10071. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10072. json_object_put(response);
  10073. }
  10074. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10075. {
  10076. json_object *data;
  10077. data = json_tokener_parse(tempdata);
  10078. if(!is_error(data))
  10079. {
  10080. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10081. {
  10082. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10083. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10084. if(gun_index < gunTotalNumber)
  10085. {
  10086. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10087. {
  10088. json_object *responsedata = json_object_new_object();
  10089. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10090. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10091. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10092. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10093. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10094. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10095. }
  10096. else
  10097. {
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10100. }
  10101. }
  10102. else
  10103. {
  10104. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10105. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10106. }
  10107. }
  10108. else
  10109. {
  10110. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10111. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10112. }
  10113. }
  10114. else
  10115. {
  10116. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10117. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10118. }
  10119. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10120. json_object_put(response);
  10121. }
  10122. else
  10123. {
  10124. // Can not find valid message id
  10125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10126. }
  10127. }
  10128. else
  10129. {
  10130. // Payload is null
  10131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10132. }
  10133. LWS_Send(message);
  10134. return result;
  10135. }
  10136. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10137. {
  10138. mtrace();
  10139. int result = FAIL;
  10140. int connectorIdInt, durationInt;
  10141. char chargingRateUnitStr[4]={0};
  10142. char comfirmstr[20];
  10143. int confirmPeriods = 0;
  10144. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10145. json_object *GetCompositeSchedule;
  10146. GetCompositeSchedule = json_tokener_parse(payload);
  10147. if(!is_error(GetCompositeSchedule))
  10148. {
  10149. // Required data
  10150. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10151. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10152. else
  10153. connectorIdInt = -1;
  10154. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10155. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10156. else
  10157. durationInt = 86400;
  10158. // Optional data
  10159. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10160. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10161. }
  10162. json_object_put(GetCompositeSchedule);
  10163. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10164. if((connectorIdInt == 0) ||
  10165. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10166. {
  10167. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10168. struct StructChargingProfile tmpProfile[1];
  10169. if(strstr(chargingRateUnitStr, "W") != NULL)
  10170. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10171. else
  10172. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10173. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10174. {
  10175. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10176. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10177. }
  10178. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10179. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10180. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10181. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10182. {
  10183. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10184. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10185. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10186. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10187. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10188. {
  10189. confirmPeriods = idx;
  10190. break;
  10191. }
  10192. }
  10193. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10194. {
  10195. confirmPeriods += 1;
  10196. }
  10197. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10198. }
  10199. else
  10200. {
  10201. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10202. }
  10203. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10204. return result;
  10205. }
  10206. int handleGetConfigurationRequest(char *uuid, char *payload)
  10207. {
  10208. mtrace();
  10209. int result = FAIL;
  10210. int MaxKeySupported = 0;
  10211. int n_keys = 0;
  10212. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10213. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10214. json_object *GetConfiguration;
  10215. GetConfiguration = json_tokener_parse(payload);
  10216. if(!is_error(GetConfiguration))
  10217. {
  10218. // Optional data
  10219. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10220. {
  10221. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10222. {
  10223. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10224. n_keys = idx + 1;
  10225. }
  10226. }
  10227. }
  10228. json_object_put(GetConfiguration);
  10229. UnknownKeynum = 0;
  10230. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10231. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10232. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10233. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10234. if(n_keys != 0)
  10235. {
  10236. for(int i=0;i<n_keys;i++)
  10237. {
  10238. getKeyValue(requestKey[i]);
  10239. }
  10240. }
  10241. else
  10242. {
  10243. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10244. getKeyValue("");
  10245. }
  10246. processUnkownKey();
  10247. sendGetConfigurationConfirmation(uuid);
  10248. return result;
  10249. }
  10250. static char fnamePlusPath[100]={0};
  10251. static char fnamePWithNoPath[60]={0};
  10252. void checkUploadLog(void)
  10253. {
  10254. FILE *fp;
  10255. /* Open the command for reading. */
  10256. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10257. if (fp == NULL) {
  10258. DEBUG_WARN("Failed to run command\n" );
  10259. exit(1);
  10260. }
  10261. int ftppathlen = 0;
  10262. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10263. int i = 0;
  10264. /* Read the output a line at a time - output it. */
  10265. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10266. if(i==0)
  10267. {
  10268. ftppathlen = strlen(fnamePlusPath);
  10269. DEBUG_INFO("%s\n", fnamePlusPath);
  10270. fnamePlusPath[ftppathlen]='\0';
  10271. break;
  10272. }
  10273. i= i+1;
  10274. }
  10275. /* close */
  10276. pclose(fp);
  10277. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10278. {
  10279. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10280. {
  10281. fnamePlusPath[k]='\0';
  10282. }
  10283. }
  10284. i=1;
  10285. //char fname[60]={0};
  10286. while(i < ftppathlen)
  10287. {
  10288. int len=ftppathlen-i;
  10289. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10290. {
  10291. DEBUG_INFO("compare '/' all right\n");
  10292. break;
  10293. }
  10294. i=i+1;
  10295. }
  10296. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10297. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10298. fnamePWithNoPath[i+1] = '\0';
  10299. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10300. {
  10301. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10302. {
  10303. fnamePWithNoPath[j]='\0';
  10304. }
  10305. }
  10306. FILE* fp1 = fopen(fnamePlusPath, "r");
  10307. if (fp1)
  10308. {
  10309. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10310. // file exists
  10311. fclose(fp1);
  10312. }
  10313. else
  10314. {
  10315. // file doesn't exist
  10316. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10317. }
  10318. }
  10319. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10320. {
  10321. mtrace();
  10322. int result = FAIL;
  10323. time_t CurrentTime;
  10324. struct tm *tm;
  10325. pthread_t th_Status;
  10326. CurrentTime = time(NULL);
  10327. tm = localtime(&CurrentTime);
  10328. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10329. 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);
  10330. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10331. if(!interLock.isGetDiagnosticGoing)
  10332. {
  10333. interLock.isGetDiagnosticGoing = 1;
  10334. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10335. sleep(1);
  10336. }
  10337. else
  10338. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10339. return result;
  10340. }
  10341. void* GetDiagnosticsProcess(void* data)
  10342. {
  10343. pthread_detach(pthread_self());
  10344. mtrace();
  10345. int retriesInt=0, retryIntervalInt=0;
  10346. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10347. 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};
  10348. int port=0;
  10349. int isSuccess = FALSE;
  10350. char cmdBuf[2048];
  10351. struct tm *tmNow;
  10352. time_t CurrentTime;
  10353. struct tm tmStart;
  10354. struct tm tmStop;
  10355. CurrentTime = time(NULL);
  10356. tmNow=localtime(&CurrentTime);
  10357. uint16_t targetYear, targetMonth;
  10358. json_object *GetDiagnostics;
  10359. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10360. GetDiagnostics = json_tokener_parse(data);
  10361. if(!is_error(GetDiagnostics))
  10362. {
  10363. // Required data
  10364. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10365. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10366. // Optional data
  10367. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10368. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10369. else
  10370. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10371. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10372. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10373. else
  10374. retryIntervalInt = 30;
  10375. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10376. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10377. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10378. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10379. }
  10380. json_object_put(GetDiagnostics);
  10381. // Pack log to compress file
  10382. 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) &&
  10383. (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))
  10384. {
  10385. // Pack system log
  10386. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10387. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10388. targetYear = tmStart.tm_year;
  10389. targetMonth = tmStart.tm_mon;
  10390. do
  10391. {
  10392. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10393. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10394. if(targetMonth+1>=13)
  10395. {
  10396. targetYear += 1;
  10397. targetMonth = 1;
  10398. }
  10399. else
  10400. {
  10401. targetMonth += 1;
  10402. }
  10403. }while((targetYear < (tmNow->tm_year+1900)) ||
  10404. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10405. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10406. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10407. system(cmdBuf);
  10408. // Pack charging & event log
  10409. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10410. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10411. targetYear = tmStart.tm_year;
  10412. targetMonth = tmStart.tm_mon;
  10413. do
  10414. {
  10415. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10416. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10417. if(targetMonth+1>=13)
  10418. {
  10419. targetYear += 1;
  10420. targetMonth = 1;
  10421. }
  10422. else
  10423. {
  10424. targetMonth += 1;
  10425. }
  10426. }while((targetYear < (tmNow->tm_year+1900)) ||
  10427. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10428. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10429. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10430. system(cmdBuf);
  10431. // Combine log file
  10432. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10433. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10434. }
  10435. else
  10436. {
  10437. system("exec /root/logPackTools 'log' 6");
  10438. }
  10439. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10440. system(cmdBuf);
  10441. checkUploadLog();
  10442. //****************location*******************/
  10443. if(strcmp(locationstr,"")==0)
  10444. {
  10445. DEBUG_INFO("location is <Empty>!\n");
  10446. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10447. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10448. goto end;
  10449. }
  10450. memset(protocol, 0, ARRAY_SIZE(protocol));
  10451. memset(user, 0, ARRAY_SIZE(user) );
  10452. memset(password, 0, ARRAY_SIZE(password));
  10453. memset(host, 0, ARRAY_SIZE(host));
  10454. memset(path, 0, ARRAY_SIZE(path));
  10455. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10456. memset(host1, 0, ARRAY_SIZE(host1));
  10457. memset(path1, 0, ARRAY_SIZE(path1));
  10458. /*location: ftp://user:password@host:port/path*/
  10459. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10460. if((access(fnamePlusPath,F_OK))!=-1)
  10461. {
  10462. DEBUG_INFO("fnamePlusPath exist.\n");
  10463. }
  10464. else
  10465. {
  10466. DEBUG_INFO("fnamePlusPath not exist!\n");
  10467. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10468. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10469. goto end;
  10470. }
  10471. if(strchr(locationstr,'@')==NULL)
  10472. {
  10473. sscanf(locationstr,
  10474. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10475. protocol, host, &port, path);
  10476. strcpy(user,"anonymous");
  10477. strcpy(password,"");
  10478. }
  10479. else
  10480. {
  10481. //DEBUG_INFO("pch=%s\n", pch);
  10482. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10483. protocol, user, password, host, &port, path);
  10484. }
  10485. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10486. {
  10487. DEBUG_INFO("protocol is not ftp/http ! \n");
  10488. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10489. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10490. goto end;
  10491. }
  10492. if(strncmp(locationstr,"http", 4) == 0)
  10493. {
  10494. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10495. sprintf(ftppath,"/%s", path);
  10496. do
  10497. {
  10498. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10499. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10500. sleep(3);
  10501. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10502. if(!isSuccess)
  10503. {
  10504. DEBUG_INFO("Diagnostics fail.\n");
  10505. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10506. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10507. sleep(retryIntervalInt);
  10508. }
  10509. else
  10510. {
  10511. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10512. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10513. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10514. }
  10515. retriesInt--;
  10516. }while((isSuccess == 0)&&(retriesInt >= 0));
  10517. }
  10518. else
  10519. {
  10520. sscanf(host,"%[^/]%s",host1, path1);
  10521. if(strlen(path) > 0)
  10522. sprintf(ftppath,"/%s", path);
  10523. else
  10524. sprintf(ftppath,"/%s", path1);
  10525. int ftppathlen=strlen(ftppath);
  10526. int i=1;
  10527. char filenametemp[50];
  10528. while(i < ftppathlen)
  10529. {
  10530. int len=ftppathlen-i;
  10531. if(ftppath[len]== 47) // '/' ascll code: 47
  10532. {
  10533. DEBUG_INFO("find '/' all right\n");
  10534. break;
  10535. }
  10536. i=i+1;
  10537. }
  10538. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10539. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10540. filenametemp[i+1] = 0;
  10541. if(port == 0)
  10542. port = 21;
  10543. do
  10544. {
  10545. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10546. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10547. sleep(3);
  10548. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10549. if(!isSuccess)
  10550. {
  10551. DEBUG_INFO("Diagnostics fail.\n");
  10552. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10553. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10554. sleep(retryIntervalInt);
  10555. }
  10556. else
  10557. {
  10558. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10559. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10560. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10561. }
  10562. retriesInt--;
  10563. }while((!isSuccess)&&(retriesInt >= 0));
  10564. }
  10565. end:
  10566. system("rm -f /mnt/*");
  10567. sleep(5);
  10568. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10569. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10570. interLock.isGetDiagnosticGoing = 0;
  10571. pthread_exit(NULL);
  10572. }
  10573. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10574. {
  10575. mtrace();
  10576. int result = FAIL;
  10577. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10578. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10579. {
  10580. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10581. locallistVersion = -1;
  10582. }
  10583. else
  10584. {
  10585. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10586. locallistVersion = 0;
  10587. OCPP_getListVerion();
  10588. }
  10589. //from db.OCPP_getListVerion
  10590. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10591. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10592. sendGetLocalListVersionConfirmation(uuid,"");
  10593. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10594. return result;
  10595. }
  10596. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10597. {
  10598. mtrace();
  10599. int result = FAIL;
  10600. int connectorIdInt=-1;
  10601. int tempIndex = 0;
  10602. int connectorIdIsNULL, chargingProfileIsNULL;
  10603. char comfirmstr[20]={0};
  10604. char cmdBuf[512];
  10605. json_object *RemoteStartTransaction;
  10606. FILE *fp;
  10607. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10608. if(server_pending == TRUE)
  10609. {
  10610. return 0;
  10611. }
  10612. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10613. RemoteStartTransaction = json_tokener_parse(payload);
  10614. if(!is_error(RemoteStartTransaction))
  10615. {
  10616. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10617. {
  10618. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10619. }
  10620. else
  10621. {
  10622. connectorIdIsNULL = TRUE;
  10623. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10624. {
  10625. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10626. {
  10627. connectorIdIsNULL = FALSE;
  10628. connectorIdInt = (gun_index+1);
  10629. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10630. break;
  10631. }
  10632. }
  10633. }
  10634. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10635. {
  10636. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10637. // Required data
  10638. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10639. // Optional data
  10640. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10641. {
  10642. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10643. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10644. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10645. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10646. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10647. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10648. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10649. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10650. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10651. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10652. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10653. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10654. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10655. {
  10656. 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")));
  10657. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10658. 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"));
  10659. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10660. 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"));
  10661. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10662. 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")));
  10663. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10664. {
  10665. 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++)
  10666. {
  10667. 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"));
  10668. 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"));
  10669. 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)
  10670. 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"));
  10671. }
  10672. }
  10673. }
  10674. }
  10675. else
  10676. {
  10677. chargingProfileIsNULL = TRUE;
  10678. }
  10679. }
  10680. }
  10681. else
  10682. {
  10683. connectorIdIsNULL = TRUE;
  10684. }
  10685. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10686. {
  10687. DEBUG_WARN("Connector id is NULL\n.");
  10688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10689. goto end;
  10690. }
  10691. /*
  10692. enum _SYSTEM_STATUS
  10693. {
  10694. S_BOOTING = 0,
  10695. S_IDLE, = 1
  10696. S_AUTHORIZING, = 2
  10697. S_REASSIGN_CHECK, = 3
  10698. S_REASSIGN, = 4
  10699. S_PRECHARGE, = 5
  10700. S_PREPARING_FOR_EV, = 6
  10701. S_PREPARING_FOR_EVSE, = 7
  10702. S_CHARGING, = 8
  10703. S_TERMINATING, = 9
  10704. S_COMPLETE, = 10
  10705. S_ALARM, = 11
  10706. S_FAULT = 12
  10707. }
  10708. */
  10709. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10710. {
  10711. //check Transaction active
  10712. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10713. {
  10714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10715. {
  10716. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10717. }
  10718. else
  10719. {
  10720. tempIndex = connectorIdInt -1;
  10721. }
  10722. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10723. {
  10724. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10725. {
  10726. 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))
  10727. {
  10728. //Reserved
  10729. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10730. }
  10731. 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))
  10732. {
  10733. //Reserved
  10734. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10736. goto end;
  10737. }
  10738. else
  10739. {
  10740. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10741. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10742. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10743. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10744. {
  10745. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10746. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10747. goto end;
  10748. }
  10749. }//END FOR ELSE
  10750. }
  10751. }// END FOR CHAdeMO_QUANTITY
  10752. }
  10753. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10754. {
  10755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10756. {
  10757. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10758. }
  10759. else
  10760. {
  10761. tempIndex = connectorIdInt -1;
  10762. }
  10763. for (int index = 0; index < CCS_QUANTITY; index++)
  10764. {
  10765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10766. {
  10767. 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))
  10768. {
  10769. //Reserved
  10770. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10771. }
  10772. 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))
  10773. {
  10774. //Reserved
  10775. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10777. goto end;
  10778. }
  10779. else
  10780. {
  10781. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10782. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10783. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10784. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10785. {
  10786. DEBUG_WARN("CCS connector not allow start\n.");
  10787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10788. goto end;
  10789. }
  10790. }// END FOR ELSE
  10791. }
  10792. }// END FOR CCS_QUANTITY
  10793. }
  10794. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10795. {
  10796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10797. {
  10798. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10799. }
  10800. else
  10801. {
  10802. tempIndex = connectorIdInt -1;
  10803. }
  10804. for (int index = 0; index < GB_QUANTITY; index++)
  10805. {
  10806. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10807. {
  10808. 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))
  10809. {
  10810. //Reserved
  10811. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10812. }
  10813. 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))
  10814. {
  10815. //Reserved
  10816. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10818. goto end;
  10819. }
  10820. else
  10821. {
  10822. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10823. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10824. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10825. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10826. {
  10827. DEBUG_WARN("GB connector not allow start\n.");
  10828. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10829. goto end;
  10830. }
  10831. }// END FOR ELSE
  10832. }
  10833. } // END FOR GB_QUANTITY
  10834. }
  10835. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10836. {
  10837. tempIndex = connectorIdInt -1;
  10838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10839. {
  10840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10841. {
  10842. 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))
  10843. {
  10844. //Reserved
  10845. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10846. }
  10847. 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))
  10848. {
  10849. //Reserved
  10850. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10851. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10852. goto end;
  10853. }
  10854. else
  10855. {
  10856. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10857. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10858. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10859. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10860. {
  10861. DEBUG_WARN("GB connector not allow start\n.");
  10862. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10863. goto end;
  10864. }
  10865. }// END FOR ELSE
  10866. }
  10867. } // END FOR GB_QUANTITY
  10868. }
  10869. else
  10870. {
  10871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10872. {
  10873. tempIndex = 2;
  10874. }
  10875. else
  10876. {
  10877. tempIndex = connectorIdInt -1;
  10878. }
  10879. for (int index = 0; index < AC_QUANTITY; index++)
  10880. {
  10881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10882. {
  10883. 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))
  10884. {
  10885. //Reserved
  10886. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10887. }
  10888. 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))
  10889. {
  10890. //Reserved
  10891. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10893. goto end;
  10894. }
  10895. else
  10896. {
  10897. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10898. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10899. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10900. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10901. {
  10902. DEBUG_WARN("AC connector not allow start\n.");
  10903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10904. goto end;
  10905. }
  10906. }//END FOR ELSE
  10907. }
  10908. }// END FOR AC_QUANTITY
  10909. }
  10910. if(chargingProfileIsNULL == FALSE)
  10911. {
  10912. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10913. {
  10914. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10916. //memset idTag
  10917. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10918. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10919. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10920. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10921. // Save profile to file
  10922. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10923. system(cmdBuf);
  10924. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10925. fp = fopen(cmdBuf, "w");
  10926. 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));
  10927. fclose(fp);
  10928. }
  10929. else
  10930. {
  10931. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10932. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10933. }
  10934. }
  10935. else
  10936. {
  10937. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10938. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10939. //memset idTag
  10940. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10941. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10942. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10943. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10944. }
  10945. }
  10946. else
  10947. {
  10948. DEBUG_WARN("Connector id over\n.");
  10949. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10950. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10951. }
  10952. end:
  10953. json_object_put(RemoteStartTransaction);
  10954. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10955. {
  10956. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10957. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10958. }
  10959. //OCPP send RemoteStartConfirmation by first.
  10960. sendRemoteStartConfirmation(uuid, comfirmstr);
  10961. return result;
  10962. }
  10963. int handleRemoteStartRequest(char *uuid, char *payload)
  10964. {
  10965. mtrace();
  10966. int result = PASS;
  10967. int connectorIdInt=-1;
  10968. int tempIndex = 0;
  10969. char comfirmstr[20]={0};
  10970. char cmdBuf[512];
  10971. json_object *RemoteStartTransaction;
  10972. FILE *fp;
  10973. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10974. if(server_pending == TRUE)
  10975. {
  10976. result = FAIL;
  10977. }
  10978. RemoteStartTransaction = json_tokener_parse(payload);
  10979. if(!is_error(RemoteStartTransaction))
  10980. {
  10981. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10982. {
  10983. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10984. }
  10985. else
  10986. {
  10987. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10988. {
  10989. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10990. {
  10991. connectorIdInt = (gun_index+1);
  10992. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10993. break;
  10994. }
  10995. }
  10996. }
  10997. if(connectorIdInt == 0)
  10998. {
  10999. DEBUG_WARN("Connector id shall not equal 0.\n");
  11000. result = FAIL;
  11001. }
  11002. else if(connectorIdInt == -1)
  11003. {
  11004. DEBUG_INFO("Connector id does not specific.\n");
  11005. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11006. {
  11007. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11008. // Required data
  11009. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11010. // Optional data
  11011. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11012. {
  11013. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11014. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11015. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11016. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11018. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11020. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11022. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11024. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11026. {
  11027. 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")));
  11028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11029. 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"));
  11030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11031. 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"));
  11032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11033. 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")));
  11034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11035. {
  11036. 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++)
  11037. {
  11038. 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"));
  11039. 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"));
  11040. 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)
  11041. 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"));
  11042. }
  11043. }
  11044. }
  11045. }
  11046. else
  11047. {
  11048. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11049. }
  11050. }
  11051. }
  11052. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11053. {
  11054. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11055. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11056. // Required data
  11057. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11058. // Optional data
  11059. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11060. {
  11061. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11062. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11063. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11064. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11066. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11067. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11068. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11069. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11070. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11071. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11072. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11073. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11074. {
  11075. 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")));
  11076. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11077. 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"));
  11078. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11079. 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"));
  11080. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11081. 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")));
  11082. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11083. {
  11084. 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++)
  11085. {
  11086. 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"));
  11087. 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"));
  11088. 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)
  11089. 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"));
  11090. }
  11091. }
  11092. }
  11093. }
  11094. else
  11095. {
  11096. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11097. }
  11098. }
  11099. else
  11100. {
  11101. DEBUG_WARN("Connector id is over maximun value.\n");
  11102. result = FAIL;
  11103. }
  11104. }
  11105. if(result == PASS)
  11106. {
  11107. if(connectorIdInt > 0)
  11108. {
  11109. //check Transaction active
  11110. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11111. {
  11112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11113. {
  11114. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11115. }
  11116. else
  11117. {
  11118. tempIndex = connectorIdInt -1;
  11119. }
  11120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11121. {
  11122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11123. {
  11124. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11125. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11126. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11127. {
  11128. //Reserved
  11129. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11130. }
  11131. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11132. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11133. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11134. {
  11135. //Reserved
  11136. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11138. goto end;
  11139. }
  11140. else
  11141. {
  11142. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11143. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11144. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11145. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11146. {
  11147. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11149. goto end;
  11150. }
  11151. }//END FOR ELSE
  11152. }
  11153. }// END FOR CHAdeMO_QUANTITY
  11154. }
  11155. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11156. {
  11157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11158. {
  11159. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11160. }
  11161. else
  11162. {
  11163. tempIndex = connectorIdInt -1;
  11164. }
  11165. for (int index = 0; index < CCS_QUANTITY; index++)
  11166. {
  11167. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11168. {
  11169. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11170. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11171. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11172. {
  11173. //Reserved
  11174. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11175. }
  11176. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11177. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11178. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11179. {
  11180. //Reserved
  11181. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11183. goto end;
  11184. }
  11185. else
  11186. {
  11187. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11188. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11189. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11190. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11191. {
  11192. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11194. goto end;
  11195. }
  11196. }// END FOR ELSE
  11197. }
  11198. }// END FOR CCS_QUANTITY
  11199. }
  11200. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11201. {
  11202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11203. {
  11204. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11205. }
  11206. else
  11207. {
  11208. tempIndex = connectorIdInt -1;
  11209. }
  11210. for (int index = 0; index < GB_QUANTITY; index++)
  11211. {
  11212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11213. {
  11214. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11215. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11216. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11217. {
  11218. //Reserved
  11219. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11220. }
  11221. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11222. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11223. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11224. {
  11225. //Reserved
  11226. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. goto end;
  11229. }
  11230. else
  11231. {
  11232. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11233. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11234. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11235. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11236. {
  11237. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11238. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11239. goto end;
  11240. }
  11241. }// END FOR ELSE
  11242. }
  11243. } // END FOR GB_QUANTITY
  11244. }
  11245. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11246. {
  11247. tempIndex = connectorIdInt -1;
  11248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11249. {
  11250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11251. {
  11252. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11253. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11254. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11255. {
  11256. //Reserved
  11257. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11258. }
  11259. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11260. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11261. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11262. {
  11263. //Reserved
  11264. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11266. goto end;
  11267. }
  11268. else
  11269. {
  11270. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11271. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11272. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11273. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11274. {
  11275. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11277. goto end;
  11278. }
  11279. }// END FOR ELSE
  11280. }
  11281. } // END FOR GB_QUANTITY
  11282. }
  11283. else
  11284. {
  11285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11286. {
  11287. tempIndex = 2;
  11288. }
  11289. else
  11290. {
  11291. tempIndex = connectorIdInt -1;
  11292. }
  11293. for (int index = 0; index < AC_QUANTITY; index++)
  11294. {
  11295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11296. {
  11297. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11298. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11299. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11300. {
  11301. //Reserved
  11302. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11303. }
  11304. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11305. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11306. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11307. {
  11308. //Reserved
  11309. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11311. goto end;
  11312. }
  11313. else
  11314. {
  11315. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11316. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11317. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11318. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11319. {
  11320. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11322. goto end;
  11323. }
  11324. }//END FOR ELSE
  11325. }
  11326. }// END FOR AC_QUANTITY
  11327. }
  11328. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11329. {
  11330. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11331. {
  11332. // Save profile to file
  11333. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11334. system(cmdBuf);
  11335. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11336. fp = fopen(cmdBuf, "w");
  11337. 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));
  11338. fclose(fp);
  11339. }
  11340. else
  11341. {
  11342. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11344. goto end;
  11345. }
  11346. }
  11347. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11349. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11350. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11351. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11352. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11353. }
  11354. else
  11355. {
  11356. uint8_t isHasIdleConnector = FALSE;
  11357. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11358. {
  11359. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11360. {
  11361. isHasIdleConnector = TRUE;
  11362. break;
  11363. }
  11364. }
  11365. if(isHasIdleConnector == TRUE)
  11366. {
  11367. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11368. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11369. {
  11370. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11371. {
  11372. // Save profile to file
  11373. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11374. system(cmdBuf);
  11375. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11376. fp = fopen(cmdBuf, "w");
  11377. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11378. fclose(fp);
  11379. refreshStartTimer(&clientTime.RemoteStartWait);
  11380. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11382. }
  11383. else
  11384. {
  11385. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11386. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11387. }
  11388. }
  11389. else
  11390. {
  11391. refreshStartTimer(&clientTime.RemoteStartWait);
  11392. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11394. }
  11395. }
  11396. else
  11397. {
  11398. DEBUG_INFO("There is not any connector is idle.\n");
  11399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11400. }
  11401. }
  11402. }
  11403. else
  11404. {
  11405. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11406. }
  11407. end:
  11408. json_object_put(RemoteStartTransaction);
  11409. sendRemoteStartConfirmation(uuid, comfirmstr);
  11410. return result;
  11411. }
  11412. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11413. {
  11414. mtrace();
  11415. int result = FAIL;
  11416. int match = FALSE;
  11417. int GunNO = 0;
  11418. int tempIndex = 0;
  11419. int transactionIdInt=0;
  11420. int transactionIdIsNULL= TRUE;
  11421. char comfirmstr[20];
  11422. json_object *RemoteStopTransaction;
  11423. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11424. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11425. if(server_pending == TRUE)
  11426. {
  11427. return 0;
  11428. }
  11429. RemoteStopTransaction = json_tokener_parse(payload);
  11430. if(!is_error(RemoteStopTransaction))
  11431. {
  11432. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11433. {
  11434. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11435. transactionIdIsNULL = FALSE;
  11436. }
  11437. }
  11438. json_object_put(RemoteStopTransaction);
  11439. if(transactionIdIsNULL == FALSE)
  11440. {
  11441. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11442. {
  11443. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11444. {
  11445. //check Transaction active
  11446. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11447. {
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11449. {
  11450. tempIndex = ((gun_index==2) ? 1: 0);
  11451. }
  11452. else
  11453. {
  11454. tempIndex = gun_index;
  11455. }
  11456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11457. {
  11458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11459. {
  11460. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11461. {
  11462. match = TRUE;
  11463. GunNO = gun_index;
  11464. }
  11465. }
  11466. }// END FOR CHAdeMO_QUANTITY
  11467. }
  11468. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11469. {
  11470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11471. {
  11472. tempIndex = ((gun_index==2) ? 1: 0);
  11473. }
  11474. else
  11475. {
  11476. tempIndex = gun_index;
  11477. }
  11478. for (int index = 0; index < CCS_QUANTITY; index++)
  11479. {
  11480. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11481. {
  11482. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11483. {
  11484. match = TRUE;
  11485. GunNO = gun_index;
  11486. }
  11487. }
  11488. }// END FOR CCS_QUANTITY
  11489. }
  11490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11491. {
  11492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11493. {
  11494. tempIndex = ((gun_index==2) ? 1: 0);
  11495. }
  11496. else
  11497. {
  11498. tempIndex = gun_index;
  11499. }
  11500. for (int index = 0; index < GB_QUANTITY; index++)
  11501. {
  11502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11503. {
  11504. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11505. {
  11506. match = TRUE;
  11507. GunNO = gun_index;
  11508. }
  11509. }
  11510. }// END FOR GB_QUANTITY
  11511. }
  11512. else if(gunType[gun_index] == GUN_TYPE_DO)
  11513. {
  11514. tempIndex = gun_index;
  11515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11516. {
  11517. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11518. {
  11519. 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
  11520. {
  11521. match = TRUE;
  11522. GunNO = gun_index;
  11523. }
  11524. }
  11525. }// END FOR GB_QUANTITY
  11526. }
  11527. else
  11528. {
  11529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11530. {
  11531. tempIndex = 2;
  11532. }
  11533. else
  11534. {
  11535. tempIndex = gun_index;
  11536. }
  11537. for (int index = 0; index < AC_QUANTITY; index++)
  11538. {
  11539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11540. {
  11541. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11542. {
  11543. match = TRUE;
  11544. GunNO = gun_index;
  11545. }
  11546. }
  11547. }// END FOR CHAdeMO_QUANTITY
  11548. } // END FOR AC ELSE
  11549. }// CHECK IF ResponseTransactionId == transactionIdInt
  11550. }//END FOR
  11551. if( match == TRUE)
  11552. {
  11553. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11555. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11556. }
  11557. else
  11558. {
  11559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11560. }
  11561. }
  11562. else
  11563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11564. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11565. return result;
  11566. }
  11567. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11568. {
  11569. mtrace();
  11570. int result = FAIL;
  11571. int connectorIdInt=0, reservationIdInt=0;
  11572. int tempIndex = 0;
  11573. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11574. char comfirmstr[20]={0};
  11575. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11576. int c = 0;
  11577. char *loc;
  11578. //char *ptr;
  11579. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11580. strcpy(sstrtemp, stringtrimspace(payload));
  11581. //***(1)connectorId ****/
  11582. c=0;
  11583. loc = strstr(sstrtemp, "connectorId");
  11584. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11585. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11586. {
  11587. sstr[c] = loc[strlen("connectorId")+2+c];
  11588. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11589. c++;
  11590. }
  11591. sstr[c] = '\0';
  11592. connectorIdInt = atoi(sstr);
  11593. //***(2)expiryDate ****/
  11594. loc = strstr(sstrtemp, "expiryDate");
  11595. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11596. c = 0;
  11597. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11598. {
  11599. sstr[c] = loc[3+strlen("expiryDate")+c];
  11600. c++;
  11601. }
  11602. sstr[c] = '\0';
  11603. strcpy(expiryDatestr, sstr);
  11604. //***(3)idTag ****/
  11605. loc = strstr(sstrtemp, "idTag");
  11606. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11607. c = 0;
  11608. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11609. {
  11610. sstr[c] = loc[3+strlen("idTag")+c];
  11611. c++;
  11612. }
  11613. sstr[c] = '\0';
  11614. strcpy(idTagstr, sstr);
  11615. //***(4)parentIdTag ****/
  11616. loc = strstr(sstrtemp, "parentIdTag");
  11617. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11618. c = 0;
  11619. if(loc == NULL)
  11620. {
  11621. strcpy(parentIdTagstr, "");
  11622. }
  11623. else
  11624. {
  11625. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11626. {
  11627. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11628. c++;
  11629. }
  11630. sstr[c] = '\0';
  11631. strcpy(parentIdTagstr, sstr);
  11632. }
  11633. //***(5)reservationId ****/
  11634. c=0;
  11635. loc = strstr(sstrtemp, "reservationId");
  11636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11637. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11638. {
  11639. sstr[c] = loc[strlen("reservationId")+2+c];
  11640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11641. c++;
  11642. }
  11643. sstr[c] = '\0';
  11644. reservationIdInt = atoi(sstr);
  11645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11646. /*
  11647. enum SYSTEM_STATUS
  11648. {
  11649. SYS_MODE_BOOTING = 0,
  11650. SYS_MODE_IDLE = 1,
  11651. SYS_MODE_AUTHORIZING = 2,
  11652. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11653. SYS_MODE_REASSIGN = 4,
  11654. SYS_MODE_PREPARING = 5,
  11655. SYS_MODE_PREPARE_FOR_EV = 6,
  11656. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11657. SYS_MODE_CHARGING = 8,
  11658. SYS_MODE_TERMINATING = 9,
  11659. SYS_MODE_COMPLETE = 10,
  11660. SYS_MODE_ALARM = 11,
  11661. SYS_MODE_FAULT = 12,
  11662. SYS_MODE_RESERVATION = 13,
  11663. SYS_MODE_BOOKING = 14,
  11664. SYS_MODE_MAINTAIN = 15,
  11665. SYS_MODE_DEBUG = 16,
  11666. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11667. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11668. SYS_MODE_UPDATE = 19
  11669. };
  11670. */
  11671. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11672. {
  11673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11674. goto end;
  11675. }
  11676. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11677. {
  11678. //check Transaction active
  11679. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11680. {
  11681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11682. {
  11683. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11684. }
  11685. else
  11686. {
  11687. tempIndex = connectorIdInt -1;
  11688. }
  11689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11690. {
  11691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11692. {
  11693. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11694. {
  11695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11696. {
  11697. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11698. {
  11699. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11701. }
  11702. 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'))
  11703. {
  11704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11705. }
  11706. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11707. {
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11709. }
  11710. else
  11711. {
  11712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11713. }
  11714. }
  11715. 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
  11716. {
  11717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11718. }
  11719. }
  11720. else
  11721. {
  11722. //replace reservation
  11723. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11725. }
  11726. }
  11727. } // END FOR CHAdeMO_QUANTITY
  11728. }
  11729. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11730. {
  11731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11732. {
  11733. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11734. }
  11735. else
  11736. {
  11737. tempIndex = connectorIdInt -1;
  11738. }
  11739. for (int index = 0; index < CCS_QUANTITY; index++)
  11740. {
  11741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11742. {
  11743. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11744. {
  11745. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11746. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11747. {
  11748. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11749. {
  11750. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11752. }
  11753. 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'))
  11754. {
  11755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11756. }
  11757. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11758. {
  11759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11760. }
  11761. else
  11762. {
  11763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11764. }
  11765. }
  11766. 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
  11767. {
  11768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11769. }
  11770. }
  11771. else
  11772. {
  11773. //replace reservation
  11774. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11776. }
  11777. }
  11778. } // END FOR CCS_QUANTITY
  11779. }
  11780. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11781. {
  11782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11783. {
  11784. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11785. }
  11786. else
  11787. {
  11788. tempIndex = connectorIdInt -1;
  11789. }
  11790. for (int index = 0; index < GB_QUANTITY; index++)
  11791. {
  11792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11793. {
  11794. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11795. {
  11796. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11797. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11798. {
  11799. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11800. {
  11801. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11803. }
  11804. 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'))
  11805. {
  11806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11807. }
  11808. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11809. {
  11810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11811. }
  11812. else
  11813. {
  11814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11815. }
  11816. }
  11817. 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
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11820. }
  11821. }
  11822. else
  11823. {
  11824. //replace reservation
  11825. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11827. }
  11828. }
  11829. }// END FOR GB_QUANTITY
  11830. }
  11831. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11832. {
  11833. tempIndex = connectorIdInt -1;
  11834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11835. {
  11836. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11837. {
  11838. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11839. {
  11840. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11841. 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
  11842. {
  11843. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11844. {
  11845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11847. }
  11848. 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'))
  11849. {
  11850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11851. }
  11852. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11853. {
  11854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11855. }
  11856. else
  11857. {
  11858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11859. }
  11860. }
  11861. 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
  11862. {
  11863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11864. }
  11865. }
  11866. else
  11867. {
  11868. //replace reservation
  11869. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11871. }
  11872. }
  11873. }// END FOR GB_QUANTITY
  11874. }
  11875. else
  11876. {
  11877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11878. {
  11879. tempIndex = 2;
  11880. }
  11881. else
  11882. {
  11883. tempIndex = (connectorIdInt -1);
  11884. }
  11885. for (int index = 0; index < AC_QUANTITY; index++)
  11886. {
  11887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11888. {
  11889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11890. {
  11891. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11892. {
  11893. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11894. {
  11895. 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))
  11896. {
  11897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11898. }
  11899. else
  11900. {
  11901. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11903. }
  11904. }
  11905. 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'))
  11906. {
  11907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11908. }
  11909. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11910. {
  11911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11912. }
  11913. else
  11914. {
  11915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11916. }
  11917. }
  11918. 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
  11919. {
  11920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11921. }
  11922. }
  11923. else
  11924. {
  11925. //replace reservation
  11926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11928. }
  11929. }
  11930. } // END FOR AC_QUANTITY
  11931. }
  11932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11933. }
  11934. else if(connectorIdInt == 0)
  11935. {
  11936. //check Transaction active
  11937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11938. {
  11939. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11940. {
  11941. 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'))
  11942. {
  11943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11944. goto end;
  11945. }
  11946. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11947. {
  11948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11949. goto end;
  11950. }
  11951. 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
  11952. {
  11953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11954. goto end;
  11955. }
  11956. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11957. {
  11958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11959. goto end;
  11960. }
  11961. }
  11962. }// END FOR CHAdeMO_QUANTITY
  11963. for (int index = 0; index < CCS_QUANTITY; index++)
  11964. {
  11965. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11966. {
  11967. 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'))
  11968. {
  11969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11970. goto end;
  11971. }
  11972. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11973. {
  11974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11975. goto end;
  11976. }
  11977. 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
  11978. {
  11979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11980. goto end;
  11981. }
  11982. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11983. {
  11984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11985. goto end;
  11986. }
  11987. }
  11988. } // END FOR CCS_QUANTITY
  11989. for (int index = 0; index < GB_QUANTITY; index++)
  11990. {
  11991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11992. {
  11993. 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'))
  11994. {
  11995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11996. goto end;
  11997. }
  11998. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11999. {
  12000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12001. goto end;
  12002. }
  12003. 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
  12004. {
  12005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12006. goto end;
  12007. }
  12008. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12009. {
  12010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12011. goto end;
  12012. }
  12013. }
  12014. } // END FOR GB_QUANTITY
  12015. for (int index = 0; index < AC_QUANTITY; index++)
  12016. {
  12017. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12018. {
  12019. 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'))
  12020. {
  12021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12022. goto end;
  12023. }
  12024. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12025. {
  12026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12027. goto end;
  12028. }
  12029. 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
  12030. {
  12031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12032. goto end;
  12033. }
  12034. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12035. {
  12036. 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))
  12037. {
  12038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12039. goto end;
  12040. }
  12041. }
  12042. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12043. {
  12044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12045. goto end;
  12046. }
  12047. }
  12048. }// END FOR AC_QUANTITY
  12049. //The connectorId is 0
  12050. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12052. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12053. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12054. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12055. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12056. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12057. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12058. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12059. result = TRUE;
  12060. return result;
  12061. }
  12062. else
  12063. {
  12064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12065. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12066. }
  12067. if(strcmp(comfirmstr,"Accepted") == 0)
  12068. {
  12069. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12070. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12071. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12072. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12073. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12074. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12075. result = TRUE;
  12076. return result;
  12077. }
  12078. end:
  12079. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12080. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12081. return result;
  12082. }
  12083. int handleResetRequest(char *uuid, char *payload)
  12084. {
  12085. mtrace();
  12086. int result = FAIL;
  12087. char sstr[10]={0},sstrtemp[30]={ 0 };
  12088. char typestr[10]={0};
  12089. char comfirmstr[20]={0};
  12090. int c = 0;
  12091. char *loc;
  12092. DEBUG_INFO("handleResetRequest...\n");
  12093. strcpy(sstrtemp, stringtrimspace(payload));
  12094. loc = strstr(sstrtemp, "type");
  12095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12096. c = 0;
  12097. while (loc[3+strlen("type")+c] != '\"')
  12098. {
  12099. sstr[c] = loc[3+strlen("type")+c];
  12100. c++;
  12101. }
  12102. sstr[c] = '\0';
  12103. strcpy(typestr,sstr);
  12104. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12105. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12106. {
  12107. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12108. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12109. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12110. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12111. }
  12112. else
  12113. {
  12114. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12115. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12116. result = PASS;
  12117. }
  12118. sendResetConfirmation(uuid, comfirmstr);
  12119. return result;
  12120. }
  12121. int handleSendLocalListRequest(char *uuid, char *payload)
  12122. {
  12123. mtrace();
  12124. int result = FAIL;
  12125. char comfirmstr[20];
  12126. int checkState_Faulted = FALSE;
  12127. json_object *SendLocalList;
  12128. DEBUG_INFO("handleSendLocalListRequest...\n");
  12129. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12130. {
  12131. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12132. goto end;
  12133. }
  12134. //check Charge Point state
  12135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12136. {
  12137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12138. {
  12139. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12140. }
  12141. }
  12142. for (int index = 0; index < CCS_QUANTITY; index++)
  12143. {
  12144. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12145. {
  12146. checkState_Faulted = TRUE; //OCPP Status
  12147. }
  12148. }
  12149. for (int index = 0; index < GB_QUANTITY; index++)
  12150. {
  12151. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12152. {
  12153. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12154. }
  12155. }
  12156. //check Charge Point state
  12157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12158. {
  12159. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12160. {
  12161. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12162. }
  12163. }
  12164. //check Charge Point state
  12165. for (int index = 0; index < AC_QUANTITY; index++)
  12166. {
  12167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12168. {
  12169. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12170. }
  12171. }
  12172. if(checkState_Faulted == TRUE)
  12173. {
  12174. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12175. goto end;
  12176. }
  12177. // Parsing payload
  12178. SendLocalList = json_tokener_parse(payload);
  12179. if(!is_error(SendLocalList))
  12180. {
  12181. // Required data
  12182. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12183. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12184. // Optional data
  12185. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12186. {
  12187. //Check UpdateType
  12188. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12189. {
  12190. //Local list full update
  12191. DEBUG_INFO("Local list full update.\n");
  12192. locallistVersion = 0;
  12193. OCPP_getListVerion();
  12194. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12195. {
  12196. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12197. goto end;
  12198. }*/
  12199. OCPP_cleanLocalList();
  12200. }
  12201. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12202. {
  12203. //Local list different update
  12204. DEBUG_INFO("Local list different update.\n");
  12205. locallistVersion = 0;
  12206. OCPP_getListVerion();
  12207. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12208. {
  12209. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12210. goto end;
  12211. }
  12212. }
  12213. else
  12214. {
  12215. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12216. goto end;
  12217. }
  12218. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12219. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12220. {
  12221. 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")));
  12222. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12223. {
  12224. 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")));
  12225. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12226. 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")));
  12227. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12228. 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")));
  12229. }
  12230. // Add to db
  12231. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12232. {
  12233. //Local list full update
  12234. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12235. idx,
  12236. ShmOCPP16Data->SendLocalList.ListVersion,
  12237. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12238. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12239. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12240. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12241. // update list
  12242. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12243. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12244. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12245. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12246. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12247. }
  12248. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12249. {
  12250. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12251. idx,
  12252. ShmOCPP16Data->SendLocalList.ListVersion,
  12253. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12254. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12255. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12256. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12257. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12258. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12259. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12260. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12261. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12262. }
  12263. }
  12264. }
  12265. else
  12266. {
  12267. //Check UpdateType
  12268. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12269. {
  12270. //Local list full update
  12271. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12272. OCPP_cleanLocalList();
  12273. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12274. goto end;
  12275. }
  12276. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12277. {
  12278. //Local list different update
  12279. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12280. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12281. goto end;
  12282. }
  12283. }
  12284. result = PASS;
  12285. }
  12286. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12287. end:
  12288. json_object_put(SendLocalList);
  12289. sendSendLocalListConfirmation(uuid, comfirmstr);
  12290. return result;
  12291. }
  12292. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12293. {
  12294. mtrace();
  12295. int result = FAIL;
  12296. struct StructSetChargingProfile SetProfileReq = {0};
  12297. int tempchargingProfileIdInt;
  12298. int tempstackLevelInt;
  12299. int chargingSchedulePeriodCount = 0;
  12300. char comfirmstr[20]={0};
  12301. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12302. char rmFileCmd[128]={0};
  12303. int profileQuantity = 0;
  12304. int replaceableProfileCnt = 0;
  12305. json_object *SetChargingProfile;
  12306. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12307. SetChargingProfile = json_tokener_parse(payload);
  12308. if(!is_error(SetChargingProfile))
  12309. {
  12310. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12311. {
  12312. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12313. }
  12314. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12315. {
  12316. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12317. {
  12318. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12319. }
  12320. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12321. {
  12322. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12323. }
  12324. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12325. {
  12326. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12327. }
  12328. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12329. {
  12330. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12331. }
  12332. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12333. {
  12334. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12335. }
  12336. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12337. {
  12338. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12339. }
  12340. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12341. {
  12342. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12343. }
  12344. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12345. {
  12346. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12347. }
  12348. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12349. {
  12350. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12351. {
  12352. 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")));
  12353. }
  12354. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12355. {
  12356. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12357. }
  12358. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12359. {
  12360. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12361. }
  12362. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12363. {
  12364. 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")));
  12365. }
  12366. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12367. {
  12368. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12369. if(chargingSchedulePeriodCount <= 10)
  12370. {
  12371. 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++)
  12372. {
  12373. 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)
  12374. {
  12375. 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"));
  12376. }
  12377. 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)
  12378. {
  12379. 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"));
  12380. }
  12381. 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)
  12382. {
  12383. 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"));
  12384. }
  12385. }
  12386. }
  12387. }
  12388. }
  12389. }
  12390. }
  12391. // Profile periods quantity check
  12392. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12393. {
  12394. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12395. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12396. goto end;
  12397. }
  12398. // Check invalid limit
  12399. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12400. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12401. {
  12402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12403. {
  12404. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12405. {
  12406. 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)))) ||
  12407. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12408. {
  12409. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12410. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12411. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12412. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12413. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12414. goto end;
  12415. }
  12416. }
  12417. }
  12418. else
  12419. {
  12420. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12421. {
  12422. 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) ||
  12423. (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)))
  12424. {
  12425. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12426. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12427. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12428. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12429. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12430. goto end;
  12431. }
  12432. }
  12433. }
  12434. }
  12435. // Profile purpose info check
  12436. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12437. {
  12438. FILE *fp;
  12439. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12440. if(SetProfileReq.ConnectorId != 0)
  12441. {
  12442. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12443. DEBUG_WARN("Profile connector id is not 0.\n");
  12444. goto end;
  12445. }
  12446. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12447. if (!fp)
  12448. {
  12449. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12450. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12451. }
  12452. else
  12453. {
  12454. char *line = NULL;
  12455. size_t len = 0;
  12456. while(getline(&line, &len, fp) != -1)
  12457. {
  12458. json_object *obj = NULL;
  12459. obj = json_tokener_parse(line);
  12460. if(is_error(obj))
  12461. {
  12462. DEBUG_ERROR("Parse txProfile from file error.\n");
  12463. }
  12464. else
  12465. {
  12466. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12467. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12468. {
  12469. profileQuantity += 1;
  12470. }
  12471. else
  12472. replaceableProfileCnt += 1;
  12473. }
  12474. }
  12475. }
  12476. fclose(fp);
  12477. }
  12478. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12479. {
  12480. FILE *fp;
  12481. char filename[128]={0};
  12482. int tmpProfileQuantity;
  12483. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12484. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12485. {
  12486. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12487. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12488. goto end;
  12489. }
  12490. if(SetProfileReq.ConnectorId == 0)
  12491. {
  12492. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12493. {
  12494. tmpProfileQuantity = 0;
  12495. memset(filename, 0, ARRAY_SIZE(filename));
  12496. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12497. fp = fopen(filename, "r");
  12498. if (!fp)
  12499. {
  12500. DEBUG_INFO("%s does not create.\n", filename);
  12501. fp = fopen(filename, "w+");
  12502. }
  12503. else
  12504. {
  12505. char *line = NULL;
  12506. size_t len = 0;
  12507. while(getline(&line, &len, fp) != -1)
  12508. {
  12509. json_object *obj = NULL;
  12510. obj = json_tokener_parse(line);
  12511. if(is_error(obj))
  12512. {
  12513. DEBUG_ERROR("Parse txProfile from file error.\n");
  12514. }
  12515. else
  12516. {
  12517. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12518. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12519. {
  12520. tmpProfileQuantity += 1;
  12521. }
  12522. else
  12523. replaceableProfileCnt += 1;
  12524. }
  12525. }
  12526. }
  12527. fclose(fp);
  12528. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12529. }
  12530. }
  12531. else
  12532. {
  12533. memset(filename, 0, ARRAY_SIZE(filename));
  12534. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12535. fp = fopen(filename, "r");
  12536. if (!fp)
  12537. {
  12538. DEBUG_INFO("%s does not create.\n", filename);
  12539. fp = fopen(filename, "w+");
  12540. }
  12541. else
  12542. {
  12543. char *line = NULL;
  12544. size_t len = 0;
  12545. while(getline(&line, &len, fp) != -1)
  12546. {
  12547. json_object *obj = NULL;
  12548. obj = json_tokener_parse(line);
  12549. if(is_error(obj))
  12550. {
  12551. DEBUG_ERROR("Parse txProfile from file error.\n");
  12552. }
  12553. else
  12554. {
  12555. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12556. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12557. {
  12558. profileQuantity += 1;
  12559. }
  12560. else
  12561. replaceableProfileCnt += 1;
  12562. }
  12563. }
  12564. }
  12565. fclose(fp);
  12566. }
  12567. }
  12568. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12569. {
  12570. int isMatchTransactiodId= FALSE;
  12571. FILE *fp;
  12572. char filename[128]={0};
  12573. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12574. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12575. if(SetProfileReq.ConnectorId == 0)
  12576. {
  12577. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12578. DEBUG_WARN("Profile connector id is 0.\n");
  12579. goto end;
  12580. }
  12581. int tempIndex = 0;
  12582. //check Transaction active
  12583. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12584. {
  12585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12586. {
  12587. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12588. }
  12589. else
  12590. {
  12591. tempIndex = SetProfileReq.ConnectorId -1;
  12592. }
  12593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12594. {
  12595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12596. {
  12597. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12598. {
  12599. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12600. {
  12601. isMatchTransactiodId = TRUE;
  12602. break;
  12603. }
  12604. }
  12605. }
  12606. }
  12607. }
  12608. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12609. {
  12610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12611. {
  12612. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12613. }
  12614. else
  12615. {
  12616. tempIndex = SetProfileReq.ConnectorId -1;
  12617. }
  12618. for (int index = 0; index < CCS_QUANTITY; index++)
  12619. {
  12620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12621. {
  12622. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12623. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12624. {
  12625. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12626. {
  12627. isMatchTransactiodId = TRUE;
  12628. break;
  12629. }
  12630. }
  12631. }
  12632. }
  12633. }
  12634. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12635. {
  12636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12637. {
  12638. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12639. }
  12640. else
  12641. {
  12642. tempIndex = SetProfileReq.ConnectorId -1;
  12643. }
  12644. for (int index = 0; index < GB_QUANTITY; index++)
  12645. {
  12646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12647. {
  12648. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12649. {
  12650. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12651. {
  12652. isMatchTransactiodId = TRUE;
  12653. break;
  12654. }
  12655. }
  12656. }
  12657. }
  12658. }
  12659. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12660. {
  12661. tempIndex = SetProfileReq.ConnectorId -1;
  12662. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12663. {
  12664. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12665. {
  12666. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12667. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12668. {
  12669. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12670. {
  12671. isMatchTransactiodId = TRUE;
  12672. break;
  12673. }
  12674. }
  12675. }
  12676. }
  12677. }
  12678. else
  12679. {
  12680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12681. {
  12682. tempIndex = 2;
  12683. }
  12684. else
  12685. {
  12686. tempIndex = (SetProfileReq.ConnectorId -1);
  12687. }
  12688. for (int index = 0; index < AC_QUANTITY; index++)
  12689. {
  12690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12691. {
  12692. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12693. {
  12694. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12695. {
  12696. isMatchTransactiodId = TRUE;
  12697. break;
  12698. }
  12699. }
  12700. }
  12701. }
  12702. }
  12703. //check Transaction active
  12704. if(isMatchTransactiodId == FALSE)
  12705. {
  12706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12707. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12708. goto end;
  12709. }
  12710. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12711. {
  12712. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12713. DEBUG_WARN("Connector id is over max gun number.\n");
  12714. goto end;
  12715. }
  12716. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12717. fp = fopen(filename, "r");
  12718. if (!fp)
  12719. {
  12720. DEBUG_INFO("%s does not create.\n", filename);
  12721. fp = fopen(filename, "w+");
  12722. }
  12723. else
  12724. {
  12725. char *line = NULL;
  12726. size_t len = 0;
  12727. while(getline(&line, &len, fp) != -1)
  12728. {
  12729. json_object *obj = NULL;
  12730. obj = json_tokener_parse(line);
  12731. if(is_error(obj))
  12732. {
  12733. DEBUG_ERROR("Parse txProfile from file error.\n");
  12734. }
  12735. else
  12736. {
  12737. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12738. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12739. {
  12740. profileQuantity += 1;
  12741. }
  12742. else
  12743. replaceableProfileCnt += 1;
  12744. }
  12745. }
  12746. }
  12747. fclose(fp);
  12748. }
  12749. // Check ChargeProfileMaxStackLevel
  12750. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12751. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12752. {
  12753. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12754. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12755. goto end;
  12756. }
  12757. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12758. {
  12759. FILE *fp;
  12760. char dataLine[4096]={0};
  12761. char fnametemp[128]={0};
  12762. int tmpProfileQuantity;
  12763. //Check ChargePointMaxProfile.json exit
  12764. profileQuantity = 0;
  12765. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12766. {
  12767. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12768. //Check Charging Profile Count
  12769. tmpProfileQuantity = 0;
  12770. while(fscanf(fp, "%s", dataLine) != EOF)
  12771. {
  12772. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12773. {
  12774. profileQuantity += 1;
  12775. tmpProfileQuantity += 1;
  12776. }
  12777. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12778. }
  12779. fclose(fp);
  12780. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12781. }
  12782. //Check TxDefaultProfile_%d.json
  12783. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12784. {
  12785. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12786. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12787. if((access(fnametemp,F_OK))!=-1)
  12788. {
  12789. fp = fopen(fnametemp, "r");
  12790. //Check Charging Profile Count
  12791. tmpProfileQuantity = 0;
  12792. while(fscanf(fp, "%s", dataLine) != EOF)
  12793. {
  12794. //DEBUG_INFO("word=%s\n",word);
  12795. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12796. {
  12797. profileQuantity += 1;
  12798. tmpProfileQuantity += 1;
  12799. }
  12800. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12801. }
  12802. fclose(fp);
  12803. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12804. }
  12805. }
  12806. //Check TxProfile_%d.json
  12807. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12808. {
  12809. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12810. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12811. if((access(fnametemp,F_OK))!=-1)
  12812. {
  12813. fp = fopen(fnametemp, "r");
  12814. //Check Charging Profile Count
  12815. tmpProfileQuantity = 0;
  12816. while(fscanf(fp, "%s", dataLine) != EOF)
  12817. {
  12818. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12819. {
  12820. profileQuantity += 1;
  12821. tmpProfileQuantity += 1;
  12822. }
  12823. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12824. }
  12825. fclose(fp);
  12826. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12827. }
  12828. }
  12829. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12830. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12831. // To check total Profile quantity
  12832. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12833. {
  12834. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12835. {
  12836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12837. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12838. goto end;
  12839. }
  12840. }
  12841. else
  12842. {
  12843. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12844. {
  12845. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12846. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12847. goto end;
  12848. }
  12849. }
  12850. }
  12851. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12852. //**********************************Write to File********************************************************/
  12853. {
  12854. FILE *infile;
  12855. FILE *outfile;
  12856. char dataLine[4096]={0};
  12857. char filename[128]={0};
  12858. int chkChar=0;
  12859. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12860. {
  12861. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12862. {
  12863. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12864. }
  12865. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12866. {
  12867. if(SetProfileReq.ConnectorId==0)
  12868. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12869. else
  12870. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12871. }
  12872. else
  12873. {
  12874. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12875. }
  12876. infile = fopen (filename, "r");
  12877. outfile = fopen (tempfile, "w");
  12878. chkChar = fgetc(infile);
  12879. rewind(infile);
  12880. if(chkChar == EOF)
  12881. {
  12882. // Profile is empty
  12883. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12884. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12885. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12886. fclose(infile);
  12887. fclose(outfile);
  12888. sprintf(rmFileCmd,"rm -f %s",filename);
  12889. system(rmFileCmd);
  12890. rename(tempfile, filename);
  12891. }
  12892. else
  12893. {
  12894. // Profile is not empty
  12895. int ChargingProfileAdded = FALSE;
  12896. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12897. {
  12898. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12899. json_object *tmpChargingProfile;
  12900. tmpChargingProfile = json_tokener_parse(dataLine);
  12901. if(!is_error(SetChargingProfile))
  12902. {
  12903. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12904. {
  12905. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12906. {
  12907. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12908. }
  12909. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12910. {
  12911. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12912. }
  12913. }
  12914. }
  12915. json_object_put(tmpChargingProfile);
  12916. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12917. {
  12918. if(ChargingProfileAdded == FALSE)
  12919. {
  12920. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12921. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12922. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12923. ChargingProfileAdded = TRUE;
  12924. }
  12925. }
  12926. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12927. {
  12928. if(ChargingProfileAdded == FALSE)
  12929. {
  12930. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12931. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12932. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12933. ChargingProfileAdded = TRUE;
  12934. }
  12935. }
  12936. else
  12937. {
  12938. fprintf(outfile,"%s\n",dataLine);
  12939. if(ChargingProfileAdded == FALSE)
  12940. {
  12941. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12942. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12943. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12944. ChargingProfileAdded = TRUE;
  12945. }
  12946. }
  12947. } // end of while loop
  12948. fclose(infile);
  12949. fclose(outfile);
  12950. sprintf(rmFileCmd,"rm -f %s",filename);
  12951. system(rmFileCmd);
  12952. rename(tempfile, filename);
  12953. }
  12954. }
  12955. sleep(1);
  12956. result = TRUE;
  12957. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12958. }
  12959. end:
  12960. json_object_put(SetChargingProfile);
  12961. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12962. {
  12963. if(SetProfileReq.ConnectorId == 0)
  12964. {
  12965. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12966. {
  12967. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12968. }
  12969. }
  12970. else
  12971. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12972. }
  12973. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12974. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12975. return result;
  12976. }
  12977. int handleTriggerMessageRequest(char *uuid, char *payload)
  12978. {
  12979. mtrace();
  12980. int result = FAIL;
  12981. int connectorIdIsNULL = FALSE;
  12982. int connectorIdInt =0;
  12983. char sstr[40]={0},sstrtemp[100]={ 0 };
  12984. char requestedMessagestr[40]={0};
  12985. char comfirmstr[20]={0};
  12986. int c = 0;
  12987. char *loc;
  12988. DEBUG_INFO("handleTriggerMessageRequest\n");
  12989. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12990. strcpy(sstrtemp, stringtrimspace(payload));
  12991. c = 0;
  12992. loc = strstr(sstrtemp, "requestedMessage");
  12993. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12994. {
  12995. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12996. c++;
  12997. }
  12998. sstr[c] = '\0';
  12999. strcpy(requestedMessagestr, sstr);
  13000. c = 0;
  13001. loc = strstr(sstrtemp, "connectorId");
  13002. if(loc == NULL)
  13003. {
  13004. connectorIdIsNULL = TRUE;
  13005. }
  13006. else
  13007. {
  13008. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13009. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13010. {
  13011. sstr[c] = loc[strlen("connectorId")+2+c];
  13012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13013. c++;
  13014. }
  13015. sstr[c] = '\0';
  13016. connectorIdInt = atoi(sstr);
  13017. }
  13018. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13019. {
  13020. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13021. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13022. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13023. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13024. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13025. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13026. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13027. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13028. {
  13029. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13030. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13031. return TRUE;
  13032. }
  13033. else
  13034. {
  13035. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13036. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13037. }
  13038. }
  13039. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13040. {
  13041. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13042. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13043. return TRUE;
  13044. }
  13045. //==========================
  13046. // Trigger message
  13047. //==========================
  13048. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13049. {
  13050. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13051. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13052. {
  13053. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13054. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13055. }
  13056. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13057. }
  13058. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13059. {
  13060. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13061. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13062. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13063. }
  13064. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13065. {
  13066. //sendBootNotificationRequest();
  13067. server_sign = FALSE;
  13068. }
  13069. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13070. {
  13071. refreshStartTimer(&clientTime.Heartbeat);
  13072. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13073. }
  13074. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13075. {
  13076. if(connectorIdIsNULL == FALSE)
  13077. {
  13078. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13079. {
  13080. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13081. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13082. }
  13083. }
  13084. else
  13085. {
  13086. for(int idx=0;idx< gunTotalNumber;idx++)
  13087. {
  13088. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13089. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13090. }
  13091. }
  13092. }
  13093. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13094. {
  13095. if(connectorIdIsNULL == FALSE)
  13096. {
  13097. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13098. {
  13099. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13100. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13101. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13102. }
  13103. }
  13104. else
  13105. {
  13106. for(int idx=0;idx< gunTotalNumber;idx++)
  13107. {
  13108. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13109. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13110. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13111. }
  13112. }
  13113. }
  13114. return result;
  13115. }
  13116. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13117. {
  13118. mtrace();
  13119. int result = FAIL;
  13120. int connectorIdInt =0;
  13121. char comfirmstr[20]={0};
  13122. int tempIndex = 0;
  13123. json_object *UnlockConnector;
  13124. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13125. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13126. UnlockConnector = json_tokener_parse(payload);
  13127. if(!is_error(UnlockConnector))
  13128. {
  13129. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13130. {
  13131. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13132. }
  13133. }
  13134. json_object_put(UnlockConnector);
  13135. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13136. if(gunTotalNumber == 0)
  13137. {
  13138. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13139. goto end;
  13140. }
  13141. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13142. {
  13143. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13144. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13145. goto end;
  13146. }
  13147. else
  13148. {
  13149. //check Transaction active
  13150. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13151. {
  13152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13153. {
  13154. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13155. }
  13156. else
  13157. {
  13158. tempIndex = connectorIdInt -1;
  13159. }
  13160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13161. {
  13162. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13163. {
  13164. //stop Transaction
  13165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13166. }
  13167. }
  13168. }
  13169. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13170. {
  13171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13172. {
  13173. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13174. }
  13175. else
  13176. {
  13177. tempIndex = connectorIdInt -1;
  13178. }
  13179. for (int index = 0; index < CCS_QUANTITY; index++)
  13180. {
  13181. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13182. {
  13183. //stop Transaction
  13184. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13185. }
  13186. }
  13187. }
  13188. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13189. {
  13190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13191. {
  13192. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13193. }
  13194. else
  13195. {
  13196. tempIndex = connectorIdInt -1;
  13197. }
  13198. for (int index = 0; index < GB_QUANTITY; index++)
  13199. {
  13200. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13201. {
  13202. //stop Transaction
  13203. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13204. }
  13205. }
  13206. }
  13207. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13208. {
  13209. tempIndex = connectorIdInt -1;
  13210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13211. {
  13212. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13213. {
  13214. //stop Transaction
  13215. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13216. }
  13217. }
  13218. }
  13219. else
  13220. {
  13221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13222. {
  13223. tempIndex = 2;
  13224. }
  13225. else
  13226. {
  13227. tempIndex = connectorIdInt-1;
  13228. }
  13229. for (int index = 0; index < AC_QUANTITY; index++)
  13230. {
  13231. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13232. {
  13233. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13234. }
  13235. }
  13236. }
  13237. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13238. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13239. result = TRUE;
  13240. return result;
  13241. }
  13242. end:
  13243. //json_object_put(obj); --- remove temporally
  13244. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13245. return result;
  13246. }
  13247. static char UpdateFirmwarepayloadData[300]={0};
  13248. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13249. {
  13250. mtrace();
  13251. int result = FAIL;
  13252. pthread_t t;
  13253. sendUpdateFirmwareConfirmation(uuid);
  13254. memset(UpdateFirmwarepayloadData, 0, 300);
  13255. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13256. if(!interLock.isUpdateFirmwareGoing)
  13257. {
  13258. interLock.isUpdateFirmwareGoing = 1;
  13259. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13260. sleep(1);
  13261. }
  13262. else
  13263. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13264. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13265. return result;
  13266. }
  13267. void *UpdateFirmwareProcess(void *data)
  13268. {
  13269. pthread_detach(pthread_self());
  13270. mtrace();
  13271. int retriesInt =0, retryIntervalInt=0;
  13272. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13273. int port=0;
  13274. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13275. int isSuccess = 0;
  13276. char ftpbuf[1024];
  13277. char temp[1024];
  13278. char * pch;
  13279. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13280. json_object *UpdateFirmware;
  13281. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13282. if(!is_error(UpdateFirmware))
  13283. {
  13284. // Required data
  13285. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13286. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13287. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13288. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13289. // Optional data
  13290. if(json_object_object_get(UpdateFirmware, "retries"))
  13291. {
  13292. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13293. }
  13294. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13295. {
  13296. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13297. }
  13298. }
  13299. json_object_put(UpdateFirmware);
  13300. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13301. memset(path, 0, ARRAY_SIZE(path));
  13302. // Wait retrieveData
  13303. if(strlen(retrieveDatestr) > 10)
  13304. {
  13305. do
  13306. {
  13307. sleep(1);
  13308. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13309. }
  13310. // Ready to download
  13311. system("rm -f /mnt/*");
  13312. if(strncmp(locationstr,"http", 4) == 0)
  13313. {
  13314. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13315. sprintf(ftppath,"/%s", path);
  13316. DEBUG_INFO("locationstr: %s\n", locationstr);
  13317. DEBUG_INFO("protocol: %s\n",protocol);
  13318. DEBUG_INFO("host: %s\n",host);
  13319. DEBUG_INFO("path: %s\n",path);
  13320. DEBUG_INFO("ftppath: %s\n",ftppath);
  13321. int ftppathlen=strlen(ftppath);
  13322. int i=1;
  13323. char filenametemp[50];
  13324. while(i < ftppathlen)
  13325. {
  13326. int len=ftppathlen-i;
  13327. if(ftppath[len]== 47) // '/' ascll code: 47
  13328. {
  13329. DEBUG_INFO("compare '/' all right\n");
  13330. break;
  13331. }
  13332. i=i+1;
  13333. }
  13334. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13335. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13336. filenametemp[i+1] = 0;
  13337. do
  13338. {
  13339. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13340. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13341. sleep(1);
  13342. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13343. if(!isSuccess)
  13344. {
  13345. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13346. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13347. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13348. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13349. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13350. }
  13351. else
  13352. {
  13353. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13354. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13355. }
  13356. retriesInt--;
  13357. }while((isSuccess == 0)&&(retriesInt >= 0));
  13358. }
  13359. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13360. {
  13361. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13362. memset(temp, 0, ARRAY_SIZE(temp));
  13363. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13364. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13365. int ftppathlen=strlen(ftpbuf);
  13366. int i=1;
  13367. char filenametemp[50];
  13368. while(i < ftppathlen)
  13369. {
  13370. int len=ftppathlen-i;
  13371. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13372. {
  13373. DEBUG_INFO(" compare '/' all right\n");
  13374. break;
  13375. }
  13376. i=i+1;
  13377. }
  13378. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13379. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13380. filenametemp[i+1] = 0;
  13381. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13382. pch=strchr(temp,'@');
  13383. if(pch==NULL)
  13384. {
  13385. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13386. protocol, host, &port, path);
  13387. strcpy(user,"anonymous");
  13388. strcpy(password,"");
  13389. }
  13390. else
  13391. {
  13392. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13393. protocol, user, password, host, &port, path);
  13394. }
  13395. sscanf(host,"%[^/]%s",host1, path1);
  13396. sprintf(ftppath,"%s", path1);
  13397. //DEBUG_INFO("protocol =%s\n",protocol);
  13398. //DEBUG_INFO("user =%s\n",user);
  13399. //DEBUG_INFO("password =%s\n",password);
  13400. //DEBUG_INFO("host1 =%s\n",host1);
  13401. //DEBUG_INFO("port =%d\n",port);
  13402. //DEBUG_INFO("path1 =%s\n",path1);
  13403. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13404. //ftpFile(host, user, password, port, ftppath, fname);
  13405. //download firmware pthred
  13406. if(port == 0)
  13407. {
  13408. port = 21;
  13409. }
  13410. do
  13411. {
  13412. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13413. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13414. sleep(1);
  13415. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13416. if(!isSuccess)
  13417. {
  13418. //BulldogUtil.sleepMs(interval*1000);
  13419. DEBUG_INFO("Update firmware request and download file fail.\n");
  13420. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13421. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13422. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13423. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13424. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13425. }
  13426. else
  13427. {
  13428. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13429. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13430. }
  13431. retriesInt--;
  13432. }while((!isSuccess)&&(retriesInt >= 0));
  13433. }
  13434. else
  13435. {
  13436. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13437. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13438. sleep(1);
  13439. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13440. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13441. }
  13442. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13443. interLock.isUpdateFirmwareGoing = 0;
  13444. pthread_exit(NULL);
  13445. }
  13446. int handleCertificateSignedRequest(char *uuid, char *payload)
  13447. {
  13448. mtrace();
  13449. int result = PASS;
  13450. json_object *CertificateSigned;
  13451. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13452. CertificateSigned = json_tokener_parse(payload);
  13453. if(!is_error(CertificateSigned))
  13454. {
  13455. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13456. }
  13457. json_object_put(CertificateSigned);
  13458. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13459. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13460. fclose(fp);
  13461. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13462. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13463. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13464. sendCertificateSignedConfirmation(uuid);
  13465. return result;
  13466. }
  13467. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13468. {
  13469. mtrace();
  13470. int result = PASS;
  13471. json_object *DeleteCertificate;
  13472. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13473. DeleteCertificate = json_tokener_parse(payload);
  13474. if(!is_error(DeleteCertificate))
  13475. {
  13476. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13477. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13478. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13479. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13480. }
  13481. json_object_put(DeleteCertificate);
  13482. /*
  13483. * TODO: Delete certificateSigned process
  13484. */
  13485. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13486. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13487. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13488. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13489. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13490. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13491. sendDeleteCertificateConfirmation(uuid);
  13492. return result;
  13493. }
  13494. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13495. {
  13496. mtrace();
  13497. int result = PASS;
  13498. json_object *ExtendedTriggerMessage;
  13499. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13500. ExtendedTriggerMessage = json_tokener_parse(payload);
  13501. if(!is_error(ExtendedTriggerMessage))
  13502. {
  13503. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13504. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13505. {
  13506. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13507. }
  13508. else
  13509. {
  13510. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13511. }
  13512. }
  13513. json_object_put(ExtendedTriggerMessage);
  13514. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13515. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13516. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13517. {
  13518. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13519. }
  13520. else
  13521. {
  13522. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13523. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13524. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13525. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13526. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13527. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13528. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13529. {
  13530. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13531. }
  13532. else
  13533. {
  13534. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13535. }
  13536. }
  13537. sendExtendedTriggerMessageConfirmation(uuid);
  13538. //==========================
  13539. // Trigger message
  13540. //==========================
  13541. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13542. {
  13543. //sendBootNotificationRequest();
  13544. server_sign = FALSE;
  13545. }
  13546. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13547. {
  13548. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13549. }
  13550. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13551. {
  13552. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13553. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13554. {
  13555. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13556. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13557. }
  13558. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13559. }
  13560. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13561. {
  13562. refreshStartTimer(&clientTime.Heartbeat);
  13563. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13564. }
  13565. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13566. {
  13567. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13568. {
  13569. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13570. }
  13571. else
  13572. {
  13573. for(int idx=0;idx< gunTotalNumber;idx++)
  13574. {
  13575. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13576. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13577. }
  13578. }
  13579. }
  13580. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13581. {
  13582. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13583. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13584. {
  13585. 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\" &");
  13586. }
  13587. }
  13588. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13589. {
  13590. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13591. {
  13592. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13593. }
  13594. else
  13595. {
  13596. for(int idx=0;idx< gunTotalNumber;idx++)
  13597. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13598. }
  13599. }
  13600. return result;
  13601. }
  13602. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13603. {
  13604. mtrace();
  13605. int result = PASS;
  13606. json_object *GetInstalledCertificateIds;
  13607. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13608. GetInstalledCertificateIds = json_tokener_parse(payload);
  13609. if(!is_error(GetInstalledCertificateIds))
  13610. {
  13611. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13612. }
  13613. json_object_put(GetInstalledCertificateIds);
  13614. /*
  13615. * TODO: Return installed certificate process
  13616. */
  13617. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13618. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13619. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13620. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13621. sendGetInstalledCertificateIdsConfirmation(uuid);
  13622. return result;
  13623. }
  13624. int handleGetLogRequest(char *uuid, char *payload)
  13625. {
  13626. mtrace();
  13627. int result = PASS;
  13628. json_object *GetLog;
  13629. DEBUG_INFO("handleGetLogRequest...\n");
  13630. GetLog = json_tokener_parse(payload);
  13631. if(!is_error(GetLog))
  13632. {
  13633. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13634. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13635. if(json_object_object_get(GetLog, "retries") != NULL)
  13636. {
  13637. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13638. }
  13639. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13640. {
  13641. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13642. }
  13643. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13644. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13645. {
  13646. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13647. }
  13648. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13649. {
  13650. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13651. }
  13652. }
  13653. json_object_put(GetLog);
  13654. /*
  13655. * TODO: Upload log process
  13656. */
  13657. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13658. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13659. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13660. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13661. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13662. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13663. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13664. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13665. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13666. sendGetLogConfirmation(uuid);
  13667. return result;
  13668. }
  13669. int handleInstallCertificateRequest(char *uuid, char *payload)
  13670. {
  13671. mtrace();
  13672. int result = PASS;
  13673. json_object *InstallCertificate;
  13674. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13675. InstallCertificate = json_tokener_parse(payload);
  13676. if(!is_error(InstallCertificate))
  13677. {
  13678. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13679. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13680. /*
  13681. * TODO: Install certificate process
  13682. */
  13683. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13684. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13685. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13686. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13687. sendInstallCertificateConfirmation(uuid);
  13688. }
  13689. json_object_put(InstallCertificate);
  13690. return result;
  13691. }
  13692. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13693. {
  13694. mtrace();
  13695. int result = PASS;
  13696. json_object *SignedUpdateFirmware;
  13697. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13698. SignedUpdateFirmware = json_tokener_parse(payload);
  13699. if(!is_error(SignedUpdateFirmware))
  13700. {
  13701. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13702. {
  13703. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13704. }
  13705. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13706. {
  13707. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13708. }
  13709. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13710. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13711. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13712. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13713. {
  13714. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13715. }
  13716. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13717. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13718. }
  13719. json_object_put(SignedUpdateFirmware);
  13720. /*
  13721. * TODO: Upgrade firmware process
  13722. */
  13723. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13724. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13725. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13726. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13727. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13728. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13729. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13730. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13731. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13732. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13733. sendInstallCertificateConfirmation(uuid);
  13734. return result;
  13735. }
  13736. int handleUnknownRequest(char *uuid, char *payload)
  13737. {
  13738. mtrace();
  13739. int result = PASS;
  13740. DEBUG_INFO("handleUnknownRequest...\n");
  13741. sendUnknownConfirmation(uuid);
  13742. result = PASS;
  13743. return result;
  13744. }
  13745. //==========================================
  13746. // Handle server response routine
  13747. //==========================================
  13748. void handleAuthorizeResponse(char *payload, int gun_index)
  13749. {
  13750. mtrace();
  13751. char expiryDatestr[36]={0};
  13752. char parentIdTagstr[21]={0};
  13753. char statusstr[20]={0};
  13754. int expiryDateISNULL=FALSE;
  13755. int parentIdTagISNULL=FALSE;
  13756. DEBUG_INFO("handleAuthorizeResponse...\n");
  13757. json_object *Authorize;
  13758. Authorize = json_tokener_parse(payload);
  13759. if(!is_error(Authorize))
  13760. {
  13761. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13762. {
  13763. // Required data
  13764. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13765. // Optional data
  13766. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13767. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13768. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13769. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13770. }
  13771. }
  13772. json_object_put(Authorize);
  13773. if(expiryDateISNULL == FALSE)
  13774. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13775. if(parentIdTagISNULL == FALSE)
  13776. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13777. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13778. //Update idTag information to authorization cache if supproted
  13779. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13780. {
  13781. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13782. }
  13783. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13784. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13785. authorizeRetryTimes = 0;
  13786. }
  13787. void handleBootNotificationResponse(char *payload, int gun_index)
  13788. {
  13789. mtrace();
  13790. char statusStr[12]={0};
  13791. char currentTimeStr[30]={0};
  13792. int intervalInt = 0;
  13793. DEBUG_INFO("handleBootNotificationResponse...\n");
  13794. json_object *BootNotification;
  13795. BootNotification = json_tokener_parse(payload);
  13796. if(!is_error(BootNotification))
  13797. {
  13798. // Required data
  13799. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13800. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13801. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13802. }
  13803. json_object_put(BootNotification);
  13804. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13805. BootNotificationInterval = intervalInt;
  13806. //write back to ShmOCPP16Data->BootNotification
  13807. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13808. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13809. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13810. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13811. {
  13812. BootNotificationInterval = 0;
  13813. if((intervalInt == 0) || (intervalInt >= 10))
  13814. {
  13815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13816. HeartBeatWaitTime = intervalInt;
  13817. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13818. }
  13819. server_sign = TRUE;
  13820. server_pending =FALSE;
  13821. }
  13822. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13823. {
  13824. server_pending = TRUE;
  13825. }
  13826. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13827. srand(time(NULL));
  13828. refreshStartTimer(&clientTime.Heartbeat);
  13829. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13830. SetOcppConnStatus(TRUE);
  13831. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13832. }
  13833. void handleDataTransferResponse(char *payload, int gun_index)
  13834. {
  13835. json_object *DataTransfer = json_tokener_parse(payload);
  13836. if(!is_error(DataTransfer))
  13837. {
  13838. // Required data
  13839. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13840. // Optional data
  13841. if(json_object_object_get(DataTransfer, "data") != NULL)
  13842. {
  13843. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13844. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13845. if(!is_error(Data))
  13846. {
  13847. if(json_object_object_get(Data, "msgId") != NULL)
  13848. {
  13849. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13850. {
  13851. 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")));
  13852. }
  13853. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13854. {
  13855. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13856. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13857. }
  13858. }
  13859. }
  13860. json_object_put(Data);
  13861. }
  13862. }
  13863. json_object_put(DataTransfer);
  13864. }
  13865. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13866. {
  13867. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13868. //struct json_object *obj;
  13869. // obj = json_tokener_parse(payload);
  13870. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13871. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13872. //No fields are defined.
  13873. }
  13874. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13875. {
  13876. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13877. //struct json_object *obj;
  13878. // obj = json_tokener_parse(payload);
  13879. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13880. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13881. //No fields are defined.
  13882. }
  13883. void handleHeartbeatResponse(char *payload, int gun_index)
  13884. {
  13885. mtrace();
  13886. DEBUG_INFO("handleHeartbeatResponse...\n");
  13887. json_object *Heartbeat;
  13888. Heartbeat = json_tokener_parse(payload);
  13889. if(!is_error(Heartbeat))
  13890. {
  13891. // Required data
  13892. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13893. }
  13894. json_object_put(Heartbeat);
  13895. if(FirstHeartBeat == 0)
  13896. {
  13897. FirstHeartBeat = 1;
  13898. DEBUG_INFO("FirstHeartBeat \n");
  13899. }
  13900. HeartBeatWithNOResponse = 0;
  13901. refreshStartTimer(&clientTime.Heartbeat);
  13902. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13903. }
  13904. void handleMeterValuesResponse(char *payload, int gun_index)
  13905. {
  13906. mtrace();
  13907. DEBUG_INFO("handleMeterValuesResponse...\n");
  13908. isQueueSendable = 1;
  13909. }
  13910. void handleStartTransactionResponse(char *payload, int gun_index)
  13911. {
  13912. mtrace();
  13913. //int transactionIdInt = 0;
  13914. FILE *outfile;
  13915. char data[100]={0};
  13916. DEBUG_INFO("handleStartTransactionResponse...\n");
  13917. json_object *StartTransaction;
  13918. StartTransaction = json_tokener_parse(payload);
  13919. if(!is_error(StartTransaction))
  13920. {
  13921. // Required data
  13922. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13923. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13924. // Optional data
  13925. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13926. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13927. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13928. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13929. }
  13930. json_object_put(StartTransaction);
  13931. isQueueSendable = 1;
  13932. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13933. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13934. //-----------Start : write to the Queue TransactionId file -----------------//
  13935. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13936. {}
  13937. else
  13938. {
  13939. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13940. if(log == NULL)
  13941. {
  13942. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13943. return ;
  13944. }
  13945. else
  13946. {
  13947. fclose(log);
  13948. }
  13949. }
  13950. // open file for writing
  13951. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13952. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13953. {
  13954. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13955. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13956. fputs(data, outfile);
  13957. fclose (outfile);
  13958. }
  13959. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13960. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13961. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13962. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13963. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13964. }
  13965. void handleStatusNotificationResponse(char *payload, int gun_index)
  13966. {
  13967. mtrace();
  13968. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13969. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13970. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13971. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13972. }
  13973. void handleStopTransactionnResponse(char *payload, int gun_index)
  13974. {
  13975. mtrace();
  13976. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13977. json_object *StopTransaction;
  13978. StopTransaction = json_tokener_parse(payload);
  13979. if(!is_error(StopTransaction))
  13980. {
  13981. // Optional data
  13982. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13983. {
  13984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13985. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13987. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13989. }
  13990. }
  13991. json_object_put(StopTransaction);
  13992. isQueueSendable = 1;
  13993. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13994. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13995. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13996. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13997. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13998. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13999. }
  14000. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14001. {
  14002. mtrace();
  14003. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14004. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14005. }
  14006. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14007. {
  14008. mtrace();
  14009. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14010. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14011. }
  14012. void handleSignCertificateResponse(char *payload, int gun_index)
  14013. {
  14014. mtrace();
  14015. DEBUG_INFO("handleSignCertificateResponse...\n");
  14016. json_object *SignCertificate;
  14017. SignCertificate = json_tokener_parse(payload);
  14018. if(!is_error(SignCertificate))
  14019. {
  14020. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14021. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14022. }
  14023. json_object_put(SignCertificate);
  14024. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14025. }
  14026. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14027. {
  14028. mtrace();
  14029. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14030. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14031. }
  14032. //==========================================
  14033. // Handle Error routine
  14034. //==========================================
  14035. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14036. {
  14037. mtrace();
  14038. #ifdef SystemLogMessage
  14039. DEBUG_INFO("errorCode: %s\n", errorCode);
  14040. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14041. DEBUG_INFO("errorDetails: %s\n", payload);
  14042. #endif
  14043. }
  14044. //===============================================
  14045. // Common routine
  14046. //===============================================
  14047. int initialConfigurationTable(void)
  14048. {
  14049. //clock_t start_t, end_t, total_t;
  14050. FILE *fp;
  14051. FILE *outfile;
  14052. char str[512]={0};
  14053. char sstr[256]={0};
  14054. int c = 0;
  14055. char *loc;
  14056. int confVersion = 15;
  14057. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14058. //start_t = clock();
  14059. //printf("Starting of the program, start_t = %ld\n", start_t);
  14060. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14061. // Check configuration file size is correct
  14062. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14063. {
  14064. struct stat st;
  14065. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14066. if(st.st_size < 3100)
  14067. {
  14068. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14069. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14070. }
  14071. }
  14072. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14073. {
  14074. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14075. if(outfile == NULL)
  14076. {
  14077. DEBUG_INFO("Error opening file\n");
  14078. return FALSE;
  14079. }
  14080. /*Core Profile*/
  14081. //AllowOfflineTxForUnknownId
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14086. //AuthorizationCacheEnabled
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14091. //AuthorizeRemoteTxRequests
  14092. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14096. //BlinkRepeat
  14097. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14101. //ClockAlignedDataInterval
  14102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14106. //ConnectionTimeOut
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14111. //GetConfigurationMaxKeys
  14112. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14116. // HeartbeatInterval
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14121. // LightIntensity
  14122. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14126. // LocalAuthorizeOffline
  14127. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14131. // LocalPreAuthorize
  14132. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14136. // MaxEnergyOnInvalidId
  14137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14141. // MeterValuesAlignedData
  14142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14145. 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" );
  14146. else
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14149. // MeterValuesAlignedDataMaxLength
  14150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14154. else
  14155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14157. // MeterValuesSampledData
  14158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14161. 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" );
  14162. else
  14163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14165. // MeterValuesSampledDataMaxLength
  14166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14170. else
  14171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14173. // MeterValueSampleInterval
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14178. // MinimumStatusDuration
  14179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14182. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14184. // NumberOfConnectors
  14185. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14188. {
  14189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14190. }
  14191. else
  14192. {
  14193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14194. }
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14196. // ResetRetries
  14197. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14201. // ConnectorPhaseRotation
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14206. // ConnectorPhaseRotationMaxLength
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14211. // StopTransactionOnEVSideDisconnect
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14216. // StopTransactionOnInvalidId
  14217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14221. // StopTxnAlignedData
  14222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14226. // StopTxnAlignedDataMaxLength
  14227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14231. // StopTxnSampledData
  14232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14236. else
  14237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14239. // StopTxnSampledDataMaxLength
  14240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14243. {
  14244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14245. }
  14246. else
  14247. {
  14248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14249. }
  14250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14251. // SupportedFeatureProfiles
  14252. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14256. // SupportedFeatureProfilesMaxLength
  14257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14261. // TransactionMessageAttempts
  14262. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14265. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14267. // TransactionMessageRetryInterval
  14268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14271. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14273. // UnlockConnectorOnEVSideDisconnect
  14274. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14278. // WebSocketPingInterval
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14283. // QueueOffLineMeterValues
  14284. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14288. // AuthorizationKey
  14289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14293. // SecurityProfile
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14298. // DefaultPrice
  14299. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14303. // CustomDisplayCostAndPrice
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14308. // CustomIdleFeeAfterStop
  14309. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14313. // TimeOffset
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14318. // NextTimeOffsetTransitionDateTime
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14323. // TimeOffsetNextTransition
  14324. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14328. // SystemUptimeSec
  14329. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14333. // FreeVend
  14334. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14338. // FreeVendIdtag
  14339. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14343. // OcppServer
  14344. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14346. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14348. // MaintainServer
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14351. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14353. // StatusNotificationPeriodically
  14354. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14358. // StatusNotificationInterval
  14359. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14363. // PreAuthAmount
  14364. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14368. // isEnableLocalPowerSharing
  14369. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14373. // PowerSharingServerIP
  14374. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14376. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14378. // EVCCID_PREFIX
  14379. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14383. // Configuration Version
  14384. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14388. //* Local Auth List Management Profile*/
  14389. #if 0
  14390. //For OCTT Test Case
  14391. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14394. #endif
  14395. #if 1
  14396. //LocalAuthListEnabled
  14397. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14401. #endif
  14402. //LocalAuthListMaxLength
  14403. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14407. //SendLocalListMaxLength
  14408. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14412. //ReserveConnectorZeroSupported
  14413. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14417. //* Smart Charging Profile */
  14418. //ChargeProfileMaxStackLevel
  14419. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14423. // ChargingScheduleAllowedChargingRateUnit
  14424. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14428. // ChargingScheduleMaxPeriods
  14429. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14433. // ConnectorSwitch3to1PhaseSupported
  14434. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14438. // MaxChargingProfilesInstalled
  14439. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14443. fclose(outfile);
  14444. }
  14445. else
  14446. {
  14447. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14448. char keystr[60]={0};
  14449. char readonlystr[10]={0};
  14450. char valuestr[256]={0};
  14451. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14452. if(fp == NULL) {
  14453. DEBUG_INFO("Error opening file");
  14454. return FALSE;
  14455. }
  14456. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14457. {
  14458. //DEBUG_INFO("Get Configuration \n");
  14459. if(strlen(str) > 0)
  14460. {
  14461. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14462. //*************************key*********************************/
  14463. if(strstr(str, "key") != NULL)
  14464. {
  14465. loc = strstr(str, "key");
  14466. c = 0;
  14467. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14468. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14469. {
  14470. sstr[c] = loc[strlen("key")+3+c];
  14471. c++;
  14472. }
  14473. sstr[c] = '\0';
  14474. strcpy(keystr,sstr);
  14475. }
  14476. //*************************readonly*********************************/
  14477. if(strstr(str, "readonly") != NULL)
  14478. {
  14479. loc = strstr(str, "readonly");
  14480. c = 0;
  14481. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14482. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14483. {
  14484. sstr[c] = loc[strlen("readonly")+2+c];
  14485. c++;
  14486. }
  14487. sstr[c] = '\0';
  14488. strcpy(readonlystr,sstr);
  14489. }
  14490. //*************************value*********************************/
  14491. if(strstr(str, "value") != NULL)
  14492. {
  14493. loc = strstr(str, "value");
  14494. c = 0;
  14495. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14496. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14497. {
  14498. sstr[c] = loc[strlen("value")+3+c];
  14499. c++;
  14500. }
  14501. sstr[c] = '\0';
  14502. strcpy(valuestr,sstr);
  14503. }
  14504. // DEBUG_INFO("keystr=%s\n",keystr);
  14505. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14506. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14507. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14508. {
  14509. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14512. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14513. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14514. }
  14515. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14516. {
  14517. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14518. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14520. }
  14521. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14522. {
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14525. }
  14526. if(strcmp(keystr, "BlinkRepeat") == 0)
  14527. {
  14528. //Charger.BlinkRepeat = Integer.parseInt(value);
  14529. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14531. }
  14532. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14533. {
  14534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14536. }
  14537. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14538. {
  14539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14541. }
  14542. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14543. {
  14544. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14546. }
  14547. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14548. {
  14549. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14551. HeartBeatWaitTime = atoi(valuestr);
  14552. }
  14553. if(strcmp(keystr, "LightIntensity") == 0)
  14554. {
  14555. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14557. }
  14558. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14559. {
  14560. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14562. }
  14563. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14564. {
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14567. }
  14568. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14569. {
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14572. }
  14573. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14574. {
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14577. }
  14578. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14579. {
  14580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14582. }
  14583. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14584. {
  14585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14587. }
  14588. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14589. {
  14590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14592. }
  14593. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14594. {
  14595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14597. }
  14598. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14599. {
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14602. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14603. }
  14604. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14605. {
  14606. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14608. }
  14609. if(strcmp(keystr, "ResetRetries") == 0)
  14610. {
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14613. }
  14614. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14615. {
  14616. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14618. }
  14619. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14620. {
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14623. }
  14624. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14625. {
  14626. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14628. }
  14629. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14630. {
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14633. }
  14634. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14635. {
  14636. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14638. }
  14639. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14640. {
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14643. }
  14644. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14645. {
  14646. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14648. }
  14649. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14650. {
  14651. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14653. }
  14654. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14655. {
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14658. }
  14659. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14660. {
  14661. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14663. }
  14664. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14665. {
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14668. TransactionMessageAttemptsValue = atoi(valuestr);
  14669. }
  14670. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14671. {
  14672. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14674. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14675. }
  14676. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14677. {
  14678. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14680. }
  14681. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14682. {
  14683. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14685. }
  14686. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14687. {
  14688. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14690. }
  14691. if(strcmp(keystr, "AuthorizationKey") == 0)
  14692. {
  14693. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14694. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14696. }
  14697. if(strcmp(keystr, "SecurityProfile") == 0)
  14698. {
  14699. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14701. }
  14702. if(strcmp(keystr, "DefaultPrice") == 0)
  14703. {
  14704. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14706. }
  14707. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14708. {
  14709. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14711. }
  14712. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14713. {
  14714. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14716. }
  14717. if(strcmp(keystr, "TimeOffset") == 0)
  14718. {
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14721. }
  14722. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14723. {
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14726. }
  14727. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14728. {
  14729. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14731. }
  14732. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14733. {
  14734. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14736. }
  14737. if(strcmp(keystr, "FreeVend") == 0)
  14738. {
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14741. }
  14742. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14743. {
  14744. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14746. }
  14747. if(strcmp(keystr, "OcppServer") == 0)
  14748. {
  14749. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14750. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14751. }
  14752. if(strcmp(keystr, "MaintainServer") == 0)
  14753. {
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14755. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14756. }
  14757. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14758. {
  14759. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14761. }
  14762. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14763. {
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14766. }
  14767. if(strcmp(keystr, "PreAuthAmount") == 0)
  14768. {
  14769. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14771. }
  14772. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14773. {
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14776. }
  14777. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14778. {
  14779. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14780. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14781. }
  14782. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14783. {
  14784. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14786. }
  14787. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14788. {
  14789. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14791. }
  14792. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14793. {
  14794. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14796. }
  14797. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14798. {
  14799. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14801. }
  14802. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14803. {
  14804. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14806. }
  14807. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14808. {
  14809. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14811. }
  14812. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14813. {
  14814. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14816. }
  14817. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14818. {
  14819. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14821. }
  14822. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14823. {
  14824. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14826. }
  14827. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14828. {
  14829. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14831. }
  14832. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14833. {
  14834. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14836. }
  14837. }
  14838. }
  14839. fclose(fp);
  14840. }
  14841. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14842. {
  14843. return PASS;
  14844. }
  14845. else
  14846. {
  14847. return FAIL;
  14848. }
  14849. }
  14850. void StoreConfigurationTable(void)
  14851. {
  14852. FILE *outfile;
  14853. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14854. if(outfile == NULL)
  14855. {
  14856. DEBUG_INFO("Error opening file");
  14857. return ;
  14858. }
  14859. /*Core Profile*/
  14860. //AllowOfflineTxForUnknownId
  14861. /*
  14862. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14863. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14866. */
  14867. //DEBUG_INFO("data=%s\n",data);
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14869. //AuthorizationCacheEnabled
  14870. /*
  14871. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14876. //AuthorizeRemoteTxRequests
  14877. /*
  14878. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14881. */
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14883. //BlinkRepeat
  14884. /*
  14885. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14888. */
  14889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14890. //ClockAlignedDataInterval
  14891. /*
  14892. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14895. */
  14896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14897. //ConnectionTimeOut
  14898. /*
  14899. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14902. */
  14903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14904. //GetConfigurationMaxKeys
  14905. /*
  14906. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14909. */
  14910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14911. // HeartbeatInterval
  14912. /*
  14913. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14916. */
  14917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14918. // LightIntensity
  14919. /*
  14920. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14923. */
  14924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14925. // LocalAuthorizeOffline
  14926. /*
  14927. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14930. */
  14931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14932. // LocalPreAuthorize
  14933. /*
  14934. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14937. */
  14938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14939. // MaxEnergyOnInvalidId
  14940. /*
  14941. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14944. */
  14945. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14947. // MeterValuesAlignedData
  14948. /*
  14949. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14952. */
  14953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14954. // MeterValuesAlignedDataMaxLength
  14955. /*
  14956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14959. */
  14960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14961. // MeterValuesSampledData
  14962. /*
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14966. */
  14967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14968. // MeterValuesSampledDataMaxLength
  14969. /*
  14970. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14973. */
  14974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14975. // MeterValueSampleInterval
  14976. /*
  14977. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14980. */
  14981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14982. // MinimumStatusDuration
  14983. /*
  14984. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14987. */
  14988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14989. // NumberOfConnectors
  14990. /*
  14991. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14994. {
  14995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14996. }
  14997. else
  14998. {
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15000. }
  15001. */
  15002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15003. // ResetRetries
  15004. /*
  15005. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15008. */
  15009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15010. // ConnectorPhaseRotation
  15011. /*
  15012. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15015. */
  15016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15017. // ConnectorPhaseRotationMaxLength
  15018. /*
  15019. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15022. */
  15023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15024. // StopTransactionOnEVSideDisconnect
  15025. /*
  15026. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15029. */
  15030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15031. // StopTransactionOnInvalidId
  15032. /*
  15033. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15036. */
  15037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15038. // StopTxnAlignedData
  15039. /*
  15040. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15043. */
  15044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15045. // StopTxnAlignedDataMaxLength
  15046. /*
  15047. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15050. */
  15051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15052. // StopTxnSampledData
  15053. /*
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15057. */
  15058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15059. // StopTxnSampledDataMaxLength
  15060. /*
  15061. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15064. */
  15065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15066. // SupportedFeatureProfiles
  15067. /*
  15068. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15071. */
  15072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15073. // SupportedFeatureProfilesMaxLength
  15074. /*
  15075. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15078. */
  15079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15080. // TransactionMessageAttempts
  15081. /*
  15082. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15085. */
  15086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15087. // TransactionMessageRetryInterval
  15088. /*
  15089. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15092. */
  15093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15094. // UnlockConnectorOnEVSideDisconnect
  15095. /*
  15096. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15099. */
  15100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15101. // WebSocketPingInterval
  15102. /*
  15103. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15106. */
  15107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15108. // QueueOffLineMeterValues
  15109. /*
  15110. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15113. */
  15114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15115. // AuthorizationKey
  15116. /*
  15117. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15120. */
  15121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15122. // SecurityProfile
  15123. /*
  15124. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15127. */
  15128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15129. // DefaultPrice
  15130. /*
  15131. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15134. */
  15135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15136. // CustomDisplayCostAndPrice
  15137. /*
  15138. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15141. */
  15142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15143. // CustomIdleFeeAfterStop
  15144. /*
  15145. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15148. */
  15149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15150. // TimeOffset
  15151. /*
  15152. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15155. */
  15156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15157. // NextTimeOffsetTransitionDateTime
  15158. /*
  15159. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15162. */
  15163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15164. // TimeOffsetNextTransition
  15165. /*
  15166. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15169. */
  15170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15171. // SystemUptimeSec
  15172. /*
  15173. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15176. */
  15177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15178. // FreeVend
  15179. /*
  15180. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15183. */
  15184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15185. // FreeVendIdtag
  15186. /*
  15187. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15190. */
  15191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15192. // OcppServer
  15193. /*
  15194. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15197. */
  15198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15199. // MaintainServer
  15200. /*
  15201. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15204. */
  15205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15206. // StatusNotificationPeriodically
  15207. /*
  15208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15211. */
  15212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15213. // StatusNotificationInterval
  15214. /*
  15215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15218. */
  15219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15220. // PreAuthAmount
  15221. /*
  15222. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15225. */
  15226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15227. // isEnableLocalPowerSharing
  15228. /*
  15229. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15232. */
  15233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15234. // PowerSharingServerIP
  15235. /*
  15236. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15239. */
  15240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15241. // EVCCID_PREFIX
  15242. /*
  15243. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15246. */
  15247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15248. // ConfigurationVersion
  15249. /*
  15250. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15253. */
  15254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15255. //* Local Auth List Management Profile*/
  15256. //LocalAuthListEnabled
  15257. /*
  15258. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15261. */
  15262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15263. //LocalAuthListMaxLength
  15264. /*
  15265. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15268. */
  15269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15270. //SendLocalListMaxLength
  15271. /*
  15272. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15275. */
  15276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15277. //ReserveConnectorZeroSupported
  15278. /*
  15279. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15282. */
  15283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15284. //* Smart Charging Profile */
  15285. //ChargeProfileMaxStackLevel
  15286. /*
  15287. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15290. */
  15291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15292. // ChargingScheduleAllowedChargingRateUnit
  15293. /*
  15294. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15297. */
  15298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15299. // ChargingScheduleMaxPeriods
  15300. /*
  15301. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15304. */
  15305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15306. // ConnectorSwitch3to1PhaseSupported
  15307. /*
  15308. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15311. */
  15312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15313. // MaxChargingProfilesInstalled
  15314. /*
  15315. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15318. */
  15319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15320. fclose(outfile);
  15321. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15322. }
  15323. void getKeyValue(char *keyReq)
  15324. {
  15325. int isEmpty = FALSE;
  15326. int isKnowKey = FALSE;
  15327. DEBUG_INFO("keyReq = %s\n", keyReq);
  15328. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15329. isEmpty = TRUE;
  15330. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15335. {
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15337. }
  15338. else
  15339. {
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15341. }
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15343. isKnowKey = TRUE;
  15344. }
  15345. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15350. {
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15352. }
  15353. else
  15354. {
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15356. }
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15358. isKnowKey = TRUE;
  15359. }
  15360. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15365. {
  15366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15367. }
  15368. else
  15369. {
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15371. }
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15373. isKnowKey = TRUE;
  15374. }
  15375. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15380. {
  15381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15382. }
  15383. else
  15384. {
  15385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15386. }
  15387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15388. isKnowKey = TRUE;
  15389. }
  15390. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15395. {
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15397. }
  15398. else
  15399. {
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15401. }
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15403. isKnowKey = TRUE;
  15404. }
  15405. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15406. {
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15412. }
  15413. else
  15414. {
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15416. }
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15418. isKnowKey = TRUE;
  15419. }
  15420. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15427. }
  15428. else
  15429. {
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15431. }
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15433. isKnowKey = TRUE;
  15434. }
  15435. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15442. }
  15443. else
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15446. }
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15448. isKnowKey = TRUE;
  15449. }
  15450. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15451. {
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15457. }
  15458. else
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15461. }
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15463. isKnowKey = TRUE;
  15464. }
  15465. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15466. {
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15472. }
  15473. else
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15476. }
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15478. isKnowKey = TRUE;
  15479. }
  15480. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15481. {
  15482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15485. {
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15487. }
  15488. else
  15489. {
  15490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15491. }
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15493. isKnowKey = TRUE;
  15494. }
  15495. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15496. {
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15500. {
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15502. }
  15503. else
  15504. {
  15505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15506. }
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15508. isKnowKey = TRUE;
  15509. }
  15510. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15511. {
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15517. }
  15518. else
  15519. {
  15520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15521. }
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15523. isKnowKey = TRUE;
  15524. }
  15525. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15526. {
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15530. {
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15532. }
  15533. else
  15534. {
  15535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15536. }
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15538. isKnowKey = TRUE;
  15539. }
  15540. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15541. {
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15545. {
  15546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15547. }
  15548. else
  15549. {
  15550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15551. }
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15553. isKnowKey = TRUE;
  15554. }
  15555. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15556. {
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15560. {
  15561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15562. }
  15563. else
  15564. {
  15565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15566. }
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15568. isKnowKey = TRUE;
  15569. }
  15570. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15571. {
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15575. {
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15577. }
  15578. else
  15579. {
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15581. }
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15583. isKnowKey = TRUE;
  15584. }
  15585. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15586. {
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15592. }
  15593. else
  15594. {
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15596. }
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15598. isKnowKey = TRUE;
  15599. }
  15600. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15601. {
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15607. }
  15608. else
  15609. {
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15611. }
  15612. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15614. isKnowKey = TRUE;
  15615. }
  15616. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15623. }
  15624. else
  15625. {
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15627. }
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15629. isKnowKey = TRUE;
  15630. }
  15631. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15632. {
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15638. }
  15639. else
  15640. {
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15642. }
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15644. isKnowKey = TRUE;
  15645. }
  15646. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15647. {
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15653. }
  15654. else
  15655. {
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15657. }
  15658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15659. isKnowKey = TRUE;
  15660. }
  15661. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15662. {
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15668. }
  15669. else
  15670. {
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15672. }
  15673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15674. isKnowKey = TRUE;
  15675. }
  15676. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15677. {
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15681. {
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15683. }
  15684. else
  15685. {
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15687. }
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15689. isKnowKey = TRUE;
  15690. }
  15691. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15692. {
  15693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15696. {
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15698. }
  15699. else
  15700. {
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15702. }
  15703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15704. isKnowKey = TRUE;
  15705. }
  15706. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15707. {
  15708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15711. {
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15713. }
  15714. else
  15715. {
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15717. }
  15718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15719. isKnowKey = TRUE;
  15720. }
  15721. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15722. {
  15723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15726. {
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15728. }
  15729. else
  15730. {
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15732. }
  15733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15734. isKnowKey = TRUE;
  15735. }
  15736. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15737. {
  15738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15741. {
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15743. }
  15744. else
  15745. {
  15746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15747. }
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15749. isKnowKey = TRUE;
  15750. }
  15751. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15752. {
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15756. {
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15758. }
  15759. else
  15760. {
  15761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15762. }
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15764. isKnowKey = TRUE;
  15765. }
  15766. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15767. {
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15771. {
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15773. }
  15774. else
  15775. {
  15776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15777. }
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15779. isKnowKey = TRUE;
  15780. }
  15781. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15782. {
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15786. {
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15788. }
  15789. else
  15790. {
  15791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15792. }
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15794. isKnowKey = TRUE;
  15795. }
  15796. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15797. {
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15801. {
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15803. }
  15804. else
  15805. {
  15806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15807. }
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15809. isKnowKey = TRUE;
  15810. }
  15811. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15812. {
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15816. {
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15818. }
  15819. else
  15820. {
  15821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15822. }
  15823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15824. isKnowKey = TRUE;
  15825. }
  15826. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15827. {
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15831. {
  15832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15833. }
  15834. else
  15835. {
  15836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15837. }
  15838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15839. isKnowKey = TRUE;
  15840. }
  15841. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15842. {
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15846. {
  15847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15848. }
  15849. else
  15850. {
  15851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15852. }
  15853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15854. isKnowKey = TRUE;
  15855. }
  15856. /*
  15857. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15858. {
  15859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15862. {
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15864. }
  15865. else
  15866. {
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15868. }
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15870. isKnowKey = TRUE;
  15871. }*/
  15872. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15873. {
  15874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15877. {
  15878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15879. }
  15880. else
  15881. {
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15883. }
  15884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15885. isKnowKey = TRUE;
  15886. }
  15887. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15888. {
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15892. {
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15894. }
  15895. else
  15896. {
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15898. }
  15899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15900. isKnowKey = TRUE;
  15901. }
  15902. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15907. {
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15909. }
  15910. else
  15911. {
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15913. }
  15914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15915. isKnowKey = TRUE;
  15916. }
  15917. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15918. {
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15922. {
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15924. }
  15925. else
  15926. {
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15928. }
  15929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15930. isKnowKey = TRUE;
  15931. }
  15932. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15933. {
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15937. {
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15939. }
  15940. else
  15941. {
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15943. }
  15944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15945. isKnowKey = TRUE;
  15946. }
  15947. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15948. {
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15952. {
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15954. }
  15955. else
  15956. {
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15958. }
  15959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15960. isKnowKey = TRUE;
  15961. }
  15962. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15963. {
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15967. {
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15969. }
  15970. else
  15971. {
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15973. }
  15974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15975. isKnowKey = TRUE;
  15976. }
  15977. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15978. {
  15979. struct sysinfo s_info;
  15980. int error = sysinfo(&s_info);
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15984. {
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15986. }
  15987. else
  15988. {
  15989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15990. }
  15991. if(error != 0)
  15992. {
  15993. DEBUG_WARN("System uptime get error: %d\n", error);
  15994. }
  15995. else
  15996. {
  15997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15998. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15999. }
  16000. isKnowKey = TRUE;
  16001. }
  16002. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16003. {
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16007. {
  16008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16009. }
  16010. else
  16011. {
  16012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16013. }
  16014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16015. isKnowKey = TRUE;
  16016. }
  16017. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16018. {
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16022. {
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16024. }
  16025. else
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16028. }
  16029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16030. isKnowKey = TRUE;
  16031. }
  16032. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16033. {
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16039. }
  16040. else
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16043. }
  16044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16045. isKnowKey = TRUE;
  16046. }
  16047. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16048. {
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16054. }
  16055. else
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16058. }
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16060. isKnowKey = TRUE;
  16061. }
  16062. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16063. {
  16064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16069. }
  16070. else
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16073. }
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16075. isKnowKey = TRUE;
  16076. }
  16077. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16078. {
  16079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16084. }
  16085. else
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16088. }
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16090. isKnowKey = TRUE;
  16091. }
  16092. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16093. {
  16094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16099. }
  16100. else
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16103. }
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16105. isKnowKey = TRUE;
  16106. }
  16107. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16108. {
  16109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16114. }
  16115. else
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16118. }
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16120. isKnowKey = TRUE;
  16121. }
  16122. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16123. {
  16124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16129. }
  16130. else
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16133. }
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16135. isKnowKey = TRUE;
  16136. }
  16137. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16138. {
  16139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16142. {
  16143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16144. }
  16145. else
  16146. {
  16147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16148. }
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16150. isKnowKey = TRUE;
  16151. }
  16152. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16153. {
  16154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16157. {
  16158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16159. }
  16160. else
  16161. {
  16162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16163. }
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16165. isKnowKey = TRUE;
  16166. }
  16167. #if 1
  16168. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16169. {
  16170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16172. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16173. {
  16174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16175. }
  16176. else
  16177. {
  16178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16179. }
  16180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16181. isKnowKey = TRUE;
  16182. }
  16183. #endif
  16184. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16185. {
  16186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16188. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16189. {
  16190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16191. }
  16192. else
  16193. {
  16194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16195. }
  16196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16197. isKnowKey = TRUE;
  16198. }
  16199. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16200. {
  16201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16203. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16204. {
  16205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16206. }
  16207. else
  16208. {
  16209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16210. }
  16211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16212. isKnowKey = TRUE;
  16213. }
  16214. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16215. {
  16216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16218. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16219. {
  16220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16221. }
  16222. else
  16223. {
  16224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16225. }
  16226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16227. isKnowKey = TRUE;
  16228. }
  16229. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16230. {
  16231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16233. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16234. {
  16235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16236. }
  16237. else
  16238. {
  16239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16240. }
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16242. isKnowKey = TRUE;
  16243. }
  16244. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16245. {
  16246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16248. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16249. {
  16250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16251. }
  16252. else
  16253. {
  16254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16255. }
  16256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16257. isKnowKey = TRUE;
  16258. }
  16259. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16260. {
  16261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16263. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16264. {
  16265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16266. }
  16267. else
  16268. {
  16269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16270. }
  16271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16272. isKnowKey = TRUE;
  16273. }
  16274. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16275. {
  16276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16278. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16279. {
  16280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16281. }
  16282. else
  16283. {
  16284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16285. }
  16286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16287. isKnowKey = TRUE;
  16288. }
  16289. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16290. {
  16291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16293. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16294. {
  16295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16296. }
  16297. else
  16298. {
  16299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16300. }
  16301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16302. isKnowKey = TRUE;
  16303. }
  16304. //=========================================================
  16305. if(!isEmpty && !isKnowKey)
  16306. {
  16307. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16308. strcpy(unknownkey[UnknownKeynum], keyReq);
  16309. UnknownKeynum = UnknownKeynum + 1;
  16310. }
  16311. }
  16312. void processUnkownKey(void)
  16313. {
  16314. DEBUG_INFO("processUnkownKey...\n");
  16315. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16316. for(int index=0; index < UnknownKeynum; index++)
  16317. {
  16318. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16319. {
  16320. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16321. }
  16322. }
  16323. }
  16324. int setKeyValue(char *key, char *value)
  16325. {
  16326. int isSuccess = NotSupported;
  16327. int check_ascii=0;
  16328. char str[501]={0};
  16329. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16330. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16331. {
  16332. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16334. {
  16335. strcpy(str, (const char*)value);
  16336. for(int i = 0; str[i]; i++){
  16337. str[i] = tolower(str[i]);
  16338. }
  16339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16340. isSuccess = ConfigurationStatus_Accepted;
  16341. }
  16342. else
  16343. {
  16344. isSuccess = ConfigurationStatus_Rejected;
  16345. }
  16346. }
  16347. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16348. {
  16349. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16351. {
  16352. strcpy(str, (const char*)value);
  16353. for(int i = 0; str[i]; i++){
  16354. str[i] = tolower(str[i]);
  16355. }
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16357. isSuccess = ConfigurationStatus_Accepted;
  16358. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16366. {
  16367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16368. {
  16369. strcpy(str, (const char*)value);
  16370. for(int i = 0; str[i]; i++)
  16371. {
  16372. str[i] = tolower(str[i]);
  16373. }
  16374. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16376. isSuccess = ConfigurationStatus_Accepted;
  16377. }
  16378. else
  16379. {
  16380. isSuccess = ConfigurationStatus_Rejected;
  16381. }
  16382. }
  16383. if(strcmp(key, "BlinkRepeat") == 0)
  16384. {
  16385. //Charger.BlinkRepeat = Integer.parseInt(value);
  16386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16387. {
  16388. check_ascii = value[0];
  16389. if( (check_ascii < 48) || (check_ascii > 57) )
  16390. {
  16391. isSuccess = ConfigurationStatus_Rejected;
  16392. }
  16393. else
  16394. {
  16395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16396. isSuccess = ConfigurationStatus_Accepted;
  16397. }
  16398. }
  16399. else
  16400. {
  16401. isSuccess = ConfigurationStatus_Rejected;
  16402. }
  16403. }
  16404. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16405. {
  16406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16407. {
  16408. check_ascii = value[0];
  16409. if( (check_ascii < 48) || (check_ascii > 57) )
  16410. {
  16411. isSuccess = ConfigurationStatus_Rejected;
  16412. }
  16413. else
  16414. {
  16415. if((atoi(value) == 0) || (atoi(value) >= 5))
  16416. {
  16417. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. else
  16422. isSuccess = ConfigurationStatus_Rejected;
  16423. }
  16424. }
  16425. else
  16426. {
  16427. isSuccess = ConfigurationStatus_Rejected;
  16428. }
  16429. }
  16430. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16431. {
  16432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16433. {
  16434. check_ascii = value[0];
  16435. if( (check_ascii < 48) || (check_ascii > 57) )
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. else
  16440. {
  16441. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16443. isSuccess = ConfigurationStatus_Accepted;
  16444. }
  16445. }
  16446. else
  16447. {
  16448. isSuccess = ConfigurationStatus_Rejected;
  16449. }
  16450. }
  16451. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16452. {
  16453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16454. {
  16455. check_ascii = value[0];
  16456. if( (check_ascii < 48) || (check_ascii > 57) )
  16457. {
  16458. isSuccess = ConfigurationStatus_Rejected;
  16459. }
  16460. else
  16461. {
  16462. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16464. isSuccess = ConfigurationStatus_Accepted;
  16465. }
  16466. }
  16467. else
  16468. {
  16469. isSuccess = ConfigurationStatus_Rejected;
  16470. }
  16471. }
  16472. if(strcmp(key, "HeartbeatInterval") == 0)
  16473. {
  16474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16475. {
  16476. check_ascii = value[0];
  16477. if( (check_ascii < 48) || (check_ascii > 57) )
  16478. {
  16479. isSuccess = ConfigurationStatus_Rejected;
  16480. }
  16481. else
  16482. {
  16483. if((atoi(value) == 0) || (atoi(value) >= 10))
  16484. {
  16485. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16487. HeartBeatWaitTime = atoi(value);
  16488. isSuccess = ConfigurationStatus_Accepted;
  16489. }
  16490. else
  16491. {
  16492. isSuccess = ConfigurationStatus_Rejected;
  16493. }
  16494. }
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. if(strcmp(key, "LightIntensity") == 0)
  16502. {
  16503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16504. {
  16505. check_ascii = value[0];
  16506. if( (check_ascii < 48) || (check_ascii > 57) )
  16507. {
  16508. isSuccess = ConfigurationStatus_Rejected;
  16509. }
  16510. else
  16511. {
  16512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16513. isSuccess = ConfigurationStatus_Accepted;
  16514. }
  16515. }
  16516. else
  16517. {
  16518. isSuccess = ConfigurationStatus_Rejected;
  16519. }
  16520. }
  16521. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16522. {
  16523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16524. {
  16525. strcpy(str, (const char*)value);
  16526. for(int i = 0; str[i]; i++)
  16527. {
  16528. str[i] = tolower(str[i]);
  16529. }
  16530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16531. isSuccess = ConfigurationStatus_Accepted;
  16532. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16533. }
  16534. else
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. }
  16539. if(strcmp(key, "LocalPreAuthorize") == 0)
  16540. {
  16541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16542. {
  16543. strcpy(str, (const char*)value);
  16544. for(int i = 0; str[i]; i++)
  16545. {
  16546. str[i] = tolower(str[i]);
  16547. }
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. }
  16551. else
  16552. {
  16553. isSuccess = ConfigurationStatus_Rejected;
  16554. }
  16555. }
  16556. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16557. {
  16558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16559. {
  16560. check_ascii = value[0];
  16561. if( (check_ascii < 48) || (check_ascii > 57) )
  16562. {
  16563. isSuccess = ConfigurationStatus_Rejected;
  16564. }
  16565. else
  16566. {
  16567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16568. isSuccess = ConfigurationStatus_Accepted;
  16569. }
  16570. }
  16571. else
  16572. {
  16573. isSuccess = ConfigurationStatus_Rejected;
  16574. }
  16575. }
  16576. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16577. {
  16578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16579. {
  16580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. }
  16583. else
  16584. {
  16585. isSuccess = ConfigurationStatus_Rejected;
  16586. }
  16587. }
  16588. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16589. {
  16590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16591. {
  16592. check_ascii = value[0];
  16593. if( (check_ascii < 48) || (check_ascii > 57) )
  16594. {
  16595. isSuccess = ConfigurationStatus_Rejected;
  16596. }
  16597. else
  16598. {
  16599. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16601. isSuccess = ConfigurationStatus_Accepted;
  16602. }
  16603. }
  16604. else
  16605. {
  16606. isSuccess = ConfigurationStatus_Rejected;
  16607. }
  16608. }
  16609. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16610. {
  16611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16612. {
  16613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16614. isSuccess = ConfigurationStatus_Accepted;
  16615. }
  16616. else
  16617. {
  16618. isSuccess = ConfigurationStatus_Rejected;
  16619. }
  16620. }
  16621. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16622. {
  16623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16624. {
  16625. check_ascii = value[0];
  16626. if( (check_ascii < 48) || (check_ascii > 57) )
  16627. {
  16628. isSuccess = ConfigurationStatus_Rejected;
  16629. }
  16630. else
  16631. {
  16632. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16634. isSuccess = ConfigurationStatus_Accepted;
  16635. }
  16636. }
  16637. else
  16638. {
  16639. isSuccess = ConfigurationStatus_Rejected;
  16640. }
  16641. }
  16642. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16643. {
  16644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16645. {
  16646. check_ascii = value[0];
  16647. if( (check_ascii < 48) || (check_ascii > 57) )
  16648. {
  16649. isSuccess = ConfigurationStatus_Rejected;
  16650. }
  16651. else
  16652. {
  16653. if((atoi(value) == 0) || (atoi(value) >= 3))
  16654. {
  16655. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16657. isSuccess = ConfigurationStatus_Accepted;
  16658. }
  16659. else
  16660. {
  16661. isSuccess = ConfigurationStatus_Rejected;
  16662. }
  16663. }
  16664. }
  16665. else
  16666. {
  16667. isSuccess = ConfigurationStatus_Rejected;
  16668. }
  16669. }
  16670. if(strcmp(key, "MinimumStatusDuration") == 0)
  16671. {
  16672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16673. {
  16674. check_ascii = value[0];
  16675. if( (check_ascii < 48) || (check_ascii > 57) )
  16676. {
  16677. isSuccess = ConfigurationStatus_Rejected;
  16678. }
  16679. else
  16680. {
  16681. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16682. {
  16683. isSuccess = ConfigurationStatus_Rejected;
  16684. }
  16685. else
  16686. {
  16687. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16689. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. }
  16693. }
  16694. else
  16695. {
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. }
  16699. if(strcmp(key, "NumberOfConnectors") == 0)
  16700. {
  16701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16702. {
  16703. check_ascii = value[0];
  16704. if( (check_ascii < 48) || (check_ascii > 57) )
  16705. {
  16706. isSuccess = ConfigurationStatus_Rejected;
  16707. }
  16708. else
  16709. {
  16710. //Charger.ResetRetries = Integer.parseInt(value);
  16711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16712. isSuccess = ConfigurationStatus_Accepted;
  16713. }
  16714. }
  16715. else
  16716. {
  16717. isSuccess = ConfigurationStatus_Rejected;
  16718. }
  16719. }
  16720. if(strcmp(key, "ResetRetries") == 0)
  16721. {
  16722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16723. {
  16724. check_ascii = value[0];
  16725. if( (check_ascii < 48) || (check_ascii > 57) )
  16726. {
  16727. isSuccess = ConfigurationStatus_Rejected;
  16728. }
  16729. else
  16730. {
  16731. //Charger.ResetRetries = Integer.parseInt(value);
  16732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16733. isSuccess = ConfigurationStatus_Accepted;
  16734. }
  16735. }
  16736. else
  16737. {
  16738. isSuccess = ConfigurationStatus_Rejected;
  16739. }
  16740. }
  16741. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16742. {
  16743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16744. {
  16745. strcpy(str, (const char*)value);
  16746. for(int i = 0; str[i]; i++)
  16747. {
  16748. str[i] = tolower(str[i]);
  16749. }
  16750. if(strcmp(str, "notapplicable")== 0)
  16751. {
  16752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16753. isSuccess = ConfigurationStatus_Accepted;
  16754. }
  16755. else if(strcmp(str, "unknown")== 0)
  16756. {
  16757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16758. isSuccess = ConfigurationStatus_Accepted;
  16759. }
  16760. else if(strcmp(str, "rst")== 0)
  16761. {
  16762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16763. isSuccess = ConfigurationStatus_Accepted;
  16764. }
  16765. else if(strcmp(str, "rts")== 0)
  16766. {
  16767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16768. isSuccess = ConfigurationStatus_Accepted;
  16769. }
  16770. else if(strcmp(str, "srt")== 0)
  16771. {
  16772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16773. isSuccess = ConfigurationStatus_Accepted;
  16774. }
  16775. else if(strcmp(str, "str")== 0)
  16776. {
  16777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16778. isSuccess = ConfigurationStatus_Accepted;
  16779. }
  16780. else if(strcmp(str, "trs")== 0)
  16781. {
  16782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16783. isSuccess = ConfigurationStatus_Accepted;
  16784. }
  16785. else if(strcmp(str, "tsr")== 0)
  16786. {
  16787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16788. isSuccess = ConfigurationStatus_Accepted;
  16789. }
  16790. else
  16791. {
  16792. isSuccess = ConfigurationStatus_Rejected;
  16793. }
  16794. }
  16795. else
  16796. {
  16797. isSuccess = ConfigurationStatus_Rejected;
  16798. }
  16799. }
  16800. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16801. {
  16802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16803. {
  16804. check_ascii = value[0];
  16805. if( (check_ascii < 48) || (check_ascii > 57) )
  16806. {
  16807. isSuccess = ConfigurationStatus_Rejected;
  16808. }
  16809. else
  16810. {
  16811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16812. isSuccess = ConfigurationStatus_Accepted;
  16813. }
  16814. }
  16815. else
  16816. {
  16817. isSuccess = ConfigurationStatus_Rejected;
  16818. }
  16819. }
  16820. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16821. {
  16822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16823. {
  16824. strcpy(str, (const char*)value);
  16825. for(int i = 0; str[i]; i++)
  16826. {
  16827. str[i] = tolower(str[i]);
  16828. }
  16829. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16831. isSuccess = ConfigurationStatus_Accepted;
  16832. }
  16833. else
  16834. {
  16835. isSuccess = ConfigurationStatus_Rejected;
  16836. }
  16837. }
  16838. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16839. {
  16840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16841. {
  16842. strcpy(str, (const char*)value);
  16843. for(int i = 0; str[i]; i++)
  16844. {
  16845. str[i] = tolower(str[i]);
  16846. }
  16847. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16849. isSuccess = ConfigurationStatus_Accepted;
  16850. }
  16851. else
  16852. {
  16853. isSuccess = ConfigurationStatus_Rejected;
  16854. }
  16855. }
  16856. if(strcmp(key, "StopTxnAlignedData") == 0)
  16857. {
  16858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16859. {
  16860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16861. isSuccess = ConfigurationStatus_Accepted;
  16862. }
  16863. else
  16864. {
  16865. isSuccess = ConfigurationStatus_Rejected;
  16866. }
  16867. }
  16868. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16869. {
  16870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16871. {
  16872. check_ascii = value[0];
  16873. if( (check_ascii < 48) || (check_ascii > 57) )
  16874. {
  16875. isSuccess = ConfigurationStatus_Rejected;
  16876. }
  16877. else
  16878. {
  16879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16880. isSuccess = ConfigurationStatus_Accepted;
  16881. }
  16882. }
  16883. else
  16884. {
  16885. isSuccess = ConfigurationStatus_Rejected;
  16886. }
  16887. }
  16888. if(strcmp(key, "StopTxnSampledData") == 0)
  16889. {
  16890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16891. {
  16892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16893. isSuccess = ConfigurationStatus_Accepted;
  16894. }
  16895. else
  16896. {
  16897. isSuccess = ConfigurationStatus_Rejected;
  16898. }
  16899. }
  16900. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16901. {
  16902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16903. {
  16904. check_ascii = value[0];
  16905. if( (check_ascii < 48) || (check_ascii > 57) )
  16906. {
  16907. isSuccess = ConfigurationStatus_Rejected;
  16908. }
  16909. else
  16910. {
  16911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16912. isSuccess = ConfigurationStatus_Accepted;
  16913. }
  16914. }
  16915. else
  16916. {
  16917. isSuccess = ConfigurationStatus_Rejected;
  16918. }
  16919. }
  16920. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16921. {
  16922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16923. {
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. else
  16928. {
  16929. isSuccess = ConfigurationStatus_Rejected;
  16930. }
  16931. }
  16932. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16933. {
  16934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16935. {
  16936. check_ascii = value[0];
  16937. if( (check_ascii < 48) || (check_ascii > 57) )
  16938. {
  16939. isSuccess = ConfigurationStatus_Rejected;
  16940. }
  16941. else
  16942. {
  16943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16944. isSuccess = ConfigurationStatus_Accepted;
  16945. }
  16946. }
  16947. else
  16948. {
  16949. isSuccess = ConfigurationStatus_Rejected;
  16950. }
  16951. }
  16952. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16953. {
  16954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16955. {
  16956. check_ascii = value[0];
  16957. if( (check_ascii < 48) || (check_ascii > 57) )
  16958. {
  16959. isSuccess = ConfigurationStatus_Rejected;
  16960. }
  16961. else
  16962. {
  16963. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16965. TransactionMessageAttemptsValue = atoi(value);
  16966. isSuccess = ConfigurationStatus_Accepted;
  16967. }
  16968. }
  16969. else
  16970. {
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. }
  16974. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16975. {
  16976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16977. {
  16978. check_ascii = value[0];
  16979. if( (check_ascii < 48) || (check_ascii > 57) )
  16980. {
  16981. isSuccess = ConfigurationStatus_Rejected;
  16982. }
  16983. else
  16984. {
  16985. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16987. TransactionMessageRetryIntervalValue = atoi(value);
  16988. isSuccess = ConfigurationStatus_Accepted;
  16989. }
  16990. }
  16991. else
  16992. {
  16993. isSuccess = ConfigurationStatus_Rejected;
  16994. }
  16995. }
  16996. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16997. {
  16998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16999. {
  17000. strcpy(str, (const char*)value);
  17001. for(int i = 0; str[i]; i++)
  17002. {
  17003. str[i] = tolower(str[i]);
  17004. }
  17005. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17007. isSuccess = ConfigurationStatus_Accepted;
  17008. }
  17009. else
  17010. {
  17011. isSuccess = ConfigurationStatus_Rejected;
  17012. }
  17013. }
  17014. if(strcmp(key, "WebSocketPingInterval") == 0)
  17015. {
  17016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17017. {
  17018. check_ascii = value[0];
  17019. if( (check_ascii < 48) || (check_ascii > 57) )
  17020. {
  17021. isSuccess = ConfigurationStatus_Rejected;
  17022. }
  17023. else
  17024. {
  17025. if((atoi(value) == 0) || (atoi(value) >= 10))
  17026. {
  17027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17028. isSuccess = ConfigurationStatus_Accepted;
  17029. }
  17030. else
  17031. isSuccess = ConfigurationStatus_Rejected;
  17032. }
  17033. }
  17034. else
  17035. {
  17036. isSuccess = ConfigurationStatus_Rejected;
  17037. }
  17038. }
  17039. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17040. {
  17041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17042. {
  17043. strcpy(str, (const char*)value);
  17044. for(int i = 0; str[i]; i++)
  17045. {
  17046. str[i] = tolower(str[i]);
  17047. }
  17048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17049. isSuccess = ConfigurationStatus_Accepted;
  17050. }
  17051. else
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. }
  17056. if(strcmp(key, "AuthorizationKey") == 0)
  17057. {
  17058. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17059. {
  17060. strcpy(str, (const char*)value);
  17061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17062. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17063. isSuccess = ConfigurationStatus_Accepted;
  17064. }
  17065. else
  17066. {
  17067. isSuccess = ConfigurationStatus_Rejected;
  17068. }
  17069. }
  17070. if(strcmp(key, "SecurityProfile") == 0)
  17071. {
  17072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17073. {
  17074. check_ascii = value[0];
  17075. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17076. {
  17077. isSuccess = ConfigurationStatus_Rejected;
  17078. }
  17079. else if(check_ascii == 0x33)
  17080. {
  17081. isSuccess = NotSupported;
  17082. }
  17083. else
  17084. {
  17085. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17086. {
  17087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17088. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17089. isSuccess = ConfigurationStatus_Accepted;
  17090. }
  17091. else
  17092. isSuccess = ConfigurationStatus_Rejected;
  17093. }
  17094. }
  17095. else
  17096. {
  17097. isSuccess = ConfigurationStatus_Rejected;
  17098. }
  17099. }
  17100. if(strcmp(key, "DefaultPrice") == 0)
  17101. {
  17102. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17103. {
  17104. strcpy(str, (const char*)value);
  17105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17106. isSuccess = ConfigurationStatus_Accepted;
  17107. }
  17108. else
  17109. {
  17110. isSuccess = ConfigurationStatus_Rejected;
  17111. }
  17112. }
  17113. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17114. {
  17115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17116. {
  17117. strcpy(str, (const char*)value);
  17118. for(int i = 0; str[i]; i++)
  17119. {
  17120. str[i] = tolower(str[i]);
  17121. }
  17122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17123. isSuccess = ConfigurationStatus_Accepted;
  17124. }
  17125. else
  17126. {
  17127. isSuccess = ConfigurationStatus_Rejected;
  17128. }
  17129. }
  17130. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17131. {
  17132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17133. {
  17134. strcpy(str, (const char*)value);
  17135. for(int i = 0; str[i]; i++)
  17136. {
  17137. str[i] = tolower(str[i]);
  17138. }
  17139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17140. isSuccess = ConfigurationStatus_Accepted;
  17141. }
  17142. else
  17143. {
  17144. isSuccess = ConfigurationStatus_Rejected;
  17145. }
  17146. }
  17147. if(strcmp(key, "TimeOffset") == 0)
  17148. {
  17149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17150. {
  17151. strcpy(str, (const char*)value);
  17152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17153. isSuccess = ConfigurationStatus_Accepted;
  17154. }
  17155. else
  17156. {
  17157. isSuccess = ConfigurationStatus_Rejected;
  17158. }
  17159. }
  17160. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17161. {
  17162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17163. {
  17164. strcpy(str, (const char*)value);
  17165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17166. isSuccess = ConfigurationStatus_Accepted;
  17167. }
  17168. else
  17169. {
  17170. isSuccess = ConfigurationStatus_Rejected;
  17171. }
  17172. }
  17173. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17174. {
  17175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17176. {
  17177. strcpy(str, (const char*)value);
  17178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17179. isSuccess = ConfigurationStatus_Accepted;
  17180. }
  17181. else
  17182. {
  17183. isSuccess = ConfigurationStatus_Rejected;
  17184. }
  17185. }
  17186. if(strcmp(key, "SystemUptimeSec") == 0)
  17187. {
  17188. isSuccess = NotSupported;
  17189. }
  17190. if(strcmp(key, "FreeVend") == 0)
  17191. {
  17192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17193. {
  17194. strcpy(str, (const char*)value);
  17195. for(int i = 0; str[i]; i++)
  17196. {
  17197. str[i] = tolower(str[i]);
  17198. }
  17199. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17201. isSuccess = ConfigurationStatus_Accepted;
  17202. }
  17203. else
  17204. {
  17205. isSuccess = ConfigurationStatus_Rejected;
  17206. }
  17207. }
  17208. if(strcmp(key, "FreeVendIdtag") == 0)
  17209. {
  17210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17211. {
  17212. strcpy(str, (const char*)value);
  17213. if(strlen(str) <= 20)
  17214. {
  17215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17216. isSuccess = ConfigurationStatus_Accepted;
  17217. }
  17218. else
  17219. {
  17220. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17221. isSuccess = ConfigurationStatus_Rejected;
  17222. }
  17223. }
  17224. else
  17225. {
  17226. isSuccess = ConfigurationStatus_Rejected;
  17227. }
  17228. }
  17229. if(strcmp(key, "OcppServer") == 0)
  17230. {
  17231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17232. {
  17233. strcpy(str, (const char*)value);
  17234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17235. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17236. isSuccess = ConfigurationStatus_Accepted;
  17237. }
  17238. else
  17239. {
  17240. isSuccess = ConfigurationStatus_Rejected;
  17241. }
  17242. }
  17243. if(strcmp(key, "MaintainServer") == 0)
  17244. {
  17245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17246. {
  17247. strcpy(str, (const char*)value);
  17248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17249. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17250. isSuccess = ConfigurationStatus_Accepted;
  17251. }
  17252. else
  17253. {
  17254. isSuccess = ConfigurationStatus_Rejected;
  17255. }
  17256. }
  17257. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17258. {
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17260. {
  17261. strcpy(str, (const char*)value);
  17262. for(int i = 0; str[i]; i++)
  17263. {
  17264. str[i] = tolower(str[i]);
  17265. }
  17266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17267. isSuccess = ConfigurationStatus_Accepted;
  17268. }
  17269. else
  17270. {
  17271. isSuccess = ConfigurationStatus_Rejected;
  17272. }
  17273. }
  17274. if(strcmp(key, "StatusNotificationInterval") == 0)
  17275. {
  17276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17277. {
  17278. check_ascii = value[0];
  17279. if( (check_ascii < 48) || (check_ascii > 57) )
  17280. {
  17281. isSuccess = ConfigurationStatus_Rejected;
  17282. }
  17283. else
  17284. {
  17285. if((atoi(value) == 0) || (atoi(value) >= 10))
  17286. {
  17287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17288. isSuccess = ConfigurationStatus_Accepted;
  17289. }
  17290. else
  17291. isSuccess = ConfigurationStatus_Rejected;
  17292. }
  17293. }
  17294. else
  17295. {
  17296. isSuccess = ConfigurationStatus_Rejected;
  17297. }
  17298. }
  17299. if(strcmp(key, "PreAuthAmount") == 0)
  17300. {
  17301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17302. {
  17303. check_ascii = value[0];
  17304. if( (check_ascii < 48) || (check_ascii > 57) )
  17305. {
  17306. isSuccess = ConfigurationStatus_Rejected;
  17307. }
  17308. else
  17309. {
  17310. if(atof(value) >= 0)
  17311. {
  17312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17313. isSuccess = ConfigurationStatus_Accepted;
  17314. }
  17315. else
  17316. isSuccess = ConfigurationStatus_Rejected;
  17317. }
  17318. }
  17319. else
  17320. {
  17321. isSuccess = ConfigurationStatus_Rejected;
  17322. }
  17323. }
  17324. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17325. {
  17326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17327. {
  17328. check_ascii = value[0];
  17329. if( (check_ascii < 48) || (check_ascii > 57) )
  17330. {
  17331. isSuccess = ConfigurationStatus_Rejected;
  17332. }
  17333. else
  17334. {
  17335. if(atoi(value) >= 0)
  17336. {
  17337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17338. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17339. isSuccess = ConfigurationStatus_Accepted;
  17340. }
  17341. else
  17342. isSuccess = ConfigurationStatus_Rejected;
  17343. }
  17344. }
  17345. else
  17346. {
  17347. isSuccess = ConfigurationStatus_Rejected;
  17348. }
  17349. }
  17350. if(strcmp(key, "PowerSharingServerIP") == 0)
  17351. {
  17352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17353. {
  17354. strcpy(str, (const char*)value);
  17355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17356. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17357. isSuccess = ConfigurationStatus_Accepted;
  17358. }
  17359. else
  17360. {
  17361. isSuccess = ConfigurationStatus_Rejected;
  17362. }
  17363. }
  17364. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17365. {
  17366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17367. {
  17368. strcpy(str, (const char*)value);
  17369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17370. isSuccess = ConfigurationStatus_Accepted;
  17371. }
  17372. else
  17373. {
  17374. isSuccess = ConfigurationStatus_Rejected;
  17375. }
  17376. }
  17377. #if 0
  17378. //For OCPP Test Case
  17379. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17380. {
  17381. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17382. {
  17383. strcpy(str, (const char*)value);
  17384. for(int i = 0; str[i]; i++)
  17385. {
  17386. str[i] = tolower(str[i]);
  17387. }
  17388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17389. isSuccess = ConfigurationStatus_Accepted;
  17390. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17391. }
  17392. else
  17393. {
  17394. isSuccess = ConfigurationStatus_Rejected;
  17395. }
  17396. }
  17397. #endif
  17398. #if 1
  17399. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17400. {
  17401. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17402. {
  17403. strcpy(str, (const char*)value);
  17404. for(int i = 0; str[i]; i++)
  17405. {
  17406. str[i] = tolower(str[i]);
  17407. }
  17408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17409. isSuccess = ConfigurationStatus_Accepted;
  17410. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17411. }
  17412. else
  17413. {
  17414. isSuccess = ConfigurationStatus_Rejected;
  17415. }
  17416. }
  17417. #endif
  17418. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17419. {
  17420. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17421. {
  17422. check_ascii = value[0];
  17423. if( (check_ascii < 48) || (check_ascii > 57) )
  17424. {
  17425. isSuccess = ConfigurationStatus_Rejected;
  17426. }
  17427. else
  17428. {
  17429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17430. isSuccess = ConfigurationStatus_Accepted;
  17431. }
  17432. }
  17433. else
  17434. {
  17435. isSuccess = ConfigurationStatus_Rejected;
  17436. }
  17437. }
  17438. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17439. {
  17440. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17441. {
  17442. check_ascii = value[0];
  17443. if( (check_ascii < 48) || (check_ascii > 57) )
  17444. {
  17445. isSuccess = ConfigurationStatus_Rejected;
  17446. }
  17447. else
  17448. {
  17449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17450. isSuccess = ConfigurationStatus_Accepted;
  17451. }
  17452. }
  17453. else
  17454. {
  17455. isSuccess = ConfigurationStatus_Rejected;
  17456. }
  17457. }
  17458. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17459. {
  17460. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17461. {
  17462. strcpy(str, (const char*)value);
  17463. for(int i = 0; str[i]; i++)
  17464. {
  17465. str[i] = tolower(str[i]);
  17466. }
  17467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17468. isSuccess = ConfigurationStatus_Accepted;
  17469. }
  17470. else
  17471. {
  17472. isSuccess = ConfigurationStatus_Rejected;
  17473. }
  17474. }
  17475. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17476. {
  17477. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17478. {
  17479. check_ascii = value[0];
  17480. if( (check_ascii < 48) || (check_ascii > 57) )
  17481. {
  17482. isSuccess = ConfigurationStatus_Rejected;
  17483. }
  17484. else
  17485. {
  17486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17487. isSuccess = ConfigurationStatus_Accepted;
  17488. }
  17489. }
  17490. else
  17491. {
  17492. isSuccess = ConfigurationStatus_Rejected;
  17493. }
  17494. }
  17495. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17496. {
  17497. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17498. {
  17499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17500. isSuccess = ConfigurationStatus_Accepted;
  17501. }
  17502. else
  17503. {
  17504. isSuccess = ConfigurationStatus_Rejected;
  17505. }
  17506. }
  17507. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17508. {
  17509. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17510. {
  17511. check_ascii = value[0];
  17512. if( (check_ascii < 48) || (check_ascii > 57) )
  17513. {
  17514. isSuccess = ConfigurationStatus_Rejected;
  17515. }
  17516. else
  17517. {
  17518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17519. isSuccess = ConfigurationStatus_Accepted;
  17520. }
  17521. }
  17522. else
  17523. {
  17524. isSuccess = ConfigurationStatus_Rejected;
  17525. }
  17526. }
  17527. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17528. {
  17529. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17530. {
  17531. strcpy(str, (const char*)value);
  17532. for(int i = 0; str[i]; i++)
  17533. {
  17534. str[i] = tolower(str[i]);
  17535. }
  17536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17537. isSuccess = ConfigurationStatus_Accepted;
  17538. }
  17539. else
  17540. {
  17541. isSuccess = ConfigurationStatus_Rejected;
  17542. }
  17543. }
  17544. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17545. {
  17546. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17547. {
  17548. check_ascii = value[0];
  17549. if( (check_ascii < 48) || (check_ascii > 57) )
  17550. {
  17551. isSuccess = ConfigurationStatus_Rejected;
  17552. }
  17553. else
  17554. {
  17555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17556. isSuccess = ConfigurationStatus_Accepted;
  17557. }
  17558. }
  17559. else
  17560. {
  17561. isSuccess = ConfigurationStatus_Rejected;
  17562. }
  17563. }
  17564. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17565. return isSuccess;
  17566. }
  17567. int TransactionMessageAttemptsGet(void)
  17568. {
  17569. return TransactionMessageAttemptsValue;
  17570. }
  17571. int FirstHeartBeatResponse(void)
  17572. {
  17573. return FirstHeartBeat;
  17574. }
  17575. int TransactionMessageRetryIntervalGet(void)
  17576. {
  17577. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17578. }
  17579. int ReadHttpStatus(int sock)
  17580. {
  17581. //char c;
  17582. char buff[1024]="",*ptr=buff+1;
  17583. int bytes_received, status;
  17584. DEBUG_INFO("Begin Response ..\n");
  17585. while((bytes_received = recv(sock, ptr, 1, 0))){
  17586. if(bytes_received==-1){
  17587. perror("ReadHttpStatus");
  17588. exit(1);
  17589. }
  17590. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17591. ptr++;
  17592. }
  17593. *ptr=0;
  17594. ptr=buff+1;
  17595. sscanf(ptr,"%*s %d ", &status);
  17596. DEBUG_INFO("%s\n",ptr);
  17597. DEBUG_INFO("status=%d\n",status);
  17598. DEBUG_INFO("End Response ..\n");
  17599. return (bytes_received>0)?status:0;
  17600. }
  17601. //the only filed that it parsed is 'Content-Length'
  17602. int ParseHeader(int sock)
  17603. {
  17604. //char c;
  17605. char buff[1024]="",*ptr=buff+4;
  17606. int bytes_received;
  17607. DEBUG_INFO("Begin HEADER ..\n");
  17608. while((bytes_received = recv(sock, ptr, 1, 0))){
  17609. if(bytes_received==-1){
  17610. perror("Parse Header");
  17611. exit(1);
  17612. }
  17613. if(
  17614. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17615. (ptr[-1]=='\r') && (*ptr=='\n' )
  17616. ) break;
  17617. ptr++;
  17618. }
  17619. *ptr=0;
  17620. ptr=buff+4;
  17621. //printf("%s",ptr);
  17622. if(bytes_received){
  17623. ptr=strstr(ptr,"Content-Length:");
  17624. if(ptr){
  17625. sscanf(ptr,"%*s %d",&bytes_received);
  17626. }else
  17627. bytes_received=-1; //unknown size
  17628. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17629. }
  17630. DEBUG_INFO("End HEADER ..\n");
  17631. return bytes_received ;
  17632. }
  17633. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17634. {
  17635. int result = TRUE;
  17636. char rmFileCmd[100]={0};
  17637. char FilePath[100]={0};
  17638. char ftpbuf[200];
  17639. int systemresult;
  17640. sprintf(FilePath,"/mnt/%s",filename);
  17641. system("ping 8.8.8.8 &");
  17642. if((access(FilePath,F_OK))!=-1)
  17643. {
  17644. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17645. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17646. system(rmFileCmd);
  17647. }
  17648. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17649. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17650. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17651. systemresult = system(ftpbuf);
  17652. if(systemresult != 0)
  17653. {
  17654. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17655. result = FALSE;
  17656. }
  17657. system("pkill ping");
  17658. return result;
  17659. }
  17660. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17661. {
  17662. int result = TRUE;
  17663. char rmFileCmd[100]={0};
  17664. char FilePath[100]={0};
  17665. char ftpbuf[200];
  17666. int systemresult;
  17667. sprintf(FilePath,"/mnt/%s",filename);
  17668. system("ping 8.8.8.8 &");
  17669. if((access(FilePath,F_OK))!=-1)
  17670. {
  17671. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17672. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17673. system(rmFileCmd);
  17674. }
  17675. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17676. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17677. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17678. systemresult = system(ftpbuf);
  17679. if(systemresult != 0)
  17680. {
  17681. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17682. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17683. systemresult = system(ftpbuf);
  17684. if(systemresult != 0)
  17685. {
  17686. DEBUG_WARN("FTP download fail!\n");
  17687. result = FALSE;
  17688. }
  17689. }
  17690. system("pkill ping");
  17691. return result;
  17692. }
  17693. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17694. {
  17695. char rmFileCmd[100]={0};
  17696. char FilePath[100]={0};
  17697. char buf[512];
  17698. int systemresult = 0;
  17699. //DEBUG_INFO("filename=%s\n",filename);
  17700. //DEBUG_INFO("url=%s\n",url);
  17701. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17702. if((access(FilePath,F_OK))!=-1)
  17703. {
  17704. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17705. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17706. system(rmFileCmd);
  17707. }
  17708. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17709. if(fp == NULL)
  17710. {
  17711. DEBUG_INFO("log is NULL\n");
  17712. return FALSE;
  17713. }
  17714. else
  17715. {
  17716. fprintf(fp, "%s\n", url);
  17717. fprintf(fp, "%s\n", filename);
  17718. fclose(fp);
  17719. }
  17720. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17721. if(phpFP == NULL)
  17722. {
  17723. DEBUG_INFO("PHP upload fail.\n");
  17724. return FALSE;
  17725. }
  17726. else
  17727. {
  17728. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17729. {
  17730. if(strstr(buf, "result") != NULL)
  17731. {
  17732. sscanf(buf, "result: %d", &systemresult);
  17733. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17734. }
  17735. }
  17736. pclose(phpFP);
  17737. }
  17738. if(systemresult != 1)
  17739. {
  17740. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17741. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17742. if(phpFP == NULL)
  17743. {
  17744. DEBUG_WARN("PHP PUT upload fail.\n");
  17745. return FALSE;
  17746. }
  17747. else
  17748. {
  17749. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17750. {
  17751. if(strstr(buf, "result") != NULL)
  17752. {
  17753. sscanf(buf, "result: %d", &systemresult);
  17754. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17755. }
  17756. }
  17757. pclose(phpFP);
  17758. }
  17759. }
  17760. if(systemresult != 1)
  17761. {
  17762. DEBUG_WARN("PHP PUT upload fail.\n");
  17763. return FALSE;
  17764. }
  17765. return TRUE;
  17766. }
  17767. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17768. {
  17769. int result = FALSE;
  17770. char ftpbuf[200];
  17771. int systemresult;
  17772. /*
  17773. // Domaind name transfer to IP address
  17774. struct hostent* server;
  17775. char *IPbuffer;
  17776. server = gethostbyname(location);
  17777. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17778. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17779. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17780. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17781. systemresult = system(ftpbuf);
  17782. if(systemresult != 0)
  17783. {
  17784. DEBUG_INFO("ftpput error!\n");
  17785. }
  17786. else
  17787. {
  17788. result = TRUE;
  17789. DEBUG_INFO("ftpput OK!\n");
  17790. }
  17791. return result;
  17792. }
  17793. int GetOcppServerURL()
  17794. {
  17795. int result = FALSE;
  17796. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17797. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17798. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17799. struct yuarel url;
  17800. char urlStr[512];
  17801. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17802. {
  17803. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17804. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17805. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17806. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17807. if(yuarel_parse(&url, urlStr) != -1)
  17808. {
  17809. sprintf(OcppProtocol, "%s", url.scheme);
  17810. sprintf(OcppHost, "%s", url.host);
  17811. if(url.path == NULL)
  17812. OcppTempPath[0] = '\0';
  17813. else
  17814. {
  17815. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17816. {
  17817. sprintf(OcppTempPath, "%s/", url.path);
  17818. }
  17819. else
  17820. {
  17821. sprintf(OcppTempPath, "%s", url.path);
  17822. }
  17823. }
  17824. if(url.port == 0)
  17825. {
  17826. if(strcmp(OcppProtocol, "wss") == 0)
  17827. OcppPort = 443;
  17828. else
  17829. OcppPort = 80;
  17830. }
  17831. else
  17832. OcppPort = url.port;
  17833. result = TRUE;
  17834. }
  17835. }
  17836. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17837. {
  17838. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17839. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17840. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17841. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17842. if(yuarel_parse(&url, urlStr) != -1)
  17843. {
  17844. sprintf(OcppProtocol, "%s", url.scheme);
  17845. sprintf(OcppHost, "%s", url.host);
  17846. if(url.path == NULL)
  17847. OcppTempPath[0] = '\0';
  17848. else
  17849. sprintf(OcppTempPath, "%s", url.path);
  17850. if(url.port == 0)
  17851. {
  17852. if(strcmp(OcppProtocol, "wss") == 0)
  17853. OcppPort = 443;
  17854. else
  17855. OcppPort = 80;
  17856. }
  17857. else
  17858. OcppPort = url.port;
  17859. result = TRUE;
  17860. }
  17861. }
  17862. else
  17863. {
  17864. strcpy(OcppHost,"");
  17865. }
  17866. return result;
  17867. }
  17868. int GetOcppPath()
  17869. {
  17870. int result = FALSE;
  17871. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17872. {
  17873. if(OcppTempPath == NULL)
  17874. {
  17875. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17876. }
  17877. else
  17878. {
  17879. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17880. }
  17881. result = TRUE;
  17882. goto End;
  17883. }
  17884. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17885. {
  17886. if(OcppTempPath == NULL)
  17887. {
  17888. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17889. }
  17890. else
  17891. {
  17892. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17893. }
  17894. result = TRUE;
  17895. goto End;
  17896. }
  17897. else
  17898. {
  17899. strcpy(OcppPath,"");
  17900. }
  17901. End:
  17902. return result;
  17903. }
  17904. int GetOcppPort()
  17905. {
  17906. return OcppPort;
  17907. }
  17908. int GetOcppConnStatus(void)
  17909. {
  17910. return ShmOCPP16Data->OcppConnStatus;
  17911. }
  17912. void SetOcppConnStatus(uint8_t status)
  17913. {
  17914. ShmOCPP16Data->OcppConnStatus = status;
  17915. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17916. }
  17917. int GetHeartBeatWithNOResponse(void)
  17918. {
  17919. return HeartBeatWithNOResponse;
  17920. }
  17921. void SetHeartBeatWithNOResponse(void)
  17922. {
  17923. HeartBeatWithNOResponse = 0;
  17924. }
  17925. void GetStartTransactionIdTag(int gun_index)
  17926. {
  17927. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17928. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17929. }
  17930. int GetStartTransactionId(int gun_index)
  17931. {
  17932. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17933. }
  17934. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17935. {
  17936. char ch;
  17937. FILE *fptr1;
  17938. int temptransactionId;
  17939. char str[100]={0};
  17940. temptransactionId = 0;
  17941. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17942. {
  17943. DEBUG_INFO("IdTag is empty.\n");
  17944. return temptransactionId;
  17945. }
  17946. /*------ Read the file ----------------*/
  17947. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17948. if (!fptr1)
  17949. {
  17950. DEBUG_INFO("QueueTransactionId file open error.\n");
  17951. //printf(" File not found or unable to open the input file!!\n");
  17952. return temptransactionId;
  17953. }
  17954. ch=fgetc(fptr1);
  17955. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17956. rewind(fptr1);
  17957. if(ch!=EOF)
  17958. {
  17959. // printf("%c",ch);
  17960. while (fgets(str, 100, fptr1) != NULL)
  17961. {
  17962. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17963. if(str[0]=='\0')
  17964. {
  17965. break;
  17966. }
  17967. char *revbuf[8] = {0}; // Variable store string split
  17968. int num = 0;// Quantity after string split
  17969. DEBUG_INFO("Transaction queue data= %s\n", str);
  17970. splitstring(str,",",revbuf,&num); // String split
  17971. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17972. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17973. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17974. DEBUG_INFO("------------------------------\n");
  17975. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17976. {
  17977. if(isStopTransaction)
  17978. {
  17979. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17980. {
  17981. temptransactionId = atoi(revbuf[2]);
  17982. //break;
  17983. }
  17984. }
  17985. else
  17986. {
  17987. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17988. {
  17989. temptransactionId = atoi(revbuf[2]);
  17990. //break;
  17991. }
  17992. }
  17993. }
  17994. }
  17995. }
  17996. else
  17997. DEBUG_INFO("EOF\n");
  17998. fclose(fptr1);
  17999. /*------- End of reading ---------------*/
  18000. return temptransactionId;
  18001. }
  18002. void SetTransactionIdZero(int transactionId)
  18003. {
  18004. char ch;
  18005. FILE *fptr1, *fptr2;
  18006. int temptransactionId = 0;
  18007. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18008. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18009. if (!fptr1)
  18010. {
  18011. //printf(" File not found or unable to open the input file!!\n");
  18012. return ;
  18013. }
  18014. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18015. if (!fptr2)
  18016. {
  18017. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18018. fclose(fptr1);
  18019. return ;
  18020. }
  18021. ch=fgetc(fptr1);
  18022. rewind(fptr1);
  18023. if(ch!=EOF)
  18024. {
  18025. // copy all contents to the temporary file except the specific line
  18026. while (fgets(str, 100, fptr1) != NULL)
  18027. {
  18028. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18029. if(str[0]=='\0')
  18030. {
  18031. break;
  18032. }
  18033. char *revbuf[8] = {0};
  18034. int num = 0;
  18035. strcpy(strtemp, str);
  18036. splitstring(str,",",revbuf,&num);
  18037. if(revbuf[2][0] != '\0')
  18038. {
  18039. temptransactionId = atoi(revbuf[2]);
  18040. if(transactionId != temptransactionId)
  18041. {
  18042. fprintf(fptr2, "%s\n", strtemp);
  18043. }
  18044. }
  18045. }
  18046. }
  18047. fclose(fptr1);
  18048. fclose(fptr2);
  18049. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18050. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18051. /*------ Read the file ----------------*/
  18052. }
  18053. int InternetDisconnect(void)
  18054. {
  18055. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18056. }
  18057. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18058. void storeTempStopTransaction(int gun_index)
  18059. {
  18060. char guid[37]={0};
  18061. int tempIndex = 0;
  18062. char TempStopTransaction[256];
  18063. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18064. DEBUG_INFO("storeTempStopTransaction...\n");
  18065. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18066. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18067. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18068. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18069. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18070. {
  18071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18072. {
  18073. tempIndex = ((gun_index==2) ? 1: 0);
  18074. }
  18075. else
  18076. {
  18077. tempIndex = gun_index;
  18078. }
  18079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18080. {
  18081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18082. {
  18083. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18084. }
  18085. }// END OF CHAdeMO_QUANTITY
  18086. }
  18087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18088. {
  18089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18090. {
  18091. tempIndex = ((gun_index==2) ? 1: 0);
  18092. }
  18093. else
  18094. {
  18095. tempIndex = gun_index;
  18096. }
  18097. for (int index = 0; index < CCS_QUANTITY; index++)
  18098. {
  18099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18100. {
  18101. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18102. }
  18103. }// END OF CCS_QUANTITY
  18104. }
  18105. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18106. {
  18107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18108. {
  18109. tempIndex = ((gun_index==2) ? 1: 0);
  18110. }
  18111. else
  18112. {
  18113. tempIndex = gun_index;
  18114. }
  18115. for (int index = 0; index < GB_QUANTITY; index++)
  18116. {
  18117. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18118. {
  18119. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18120. }
  18121. }// END OF GB_QUANTITY
  18122. }
  18123. else if(gunType[gun_index] == GUN_TYPE_DO)
  18124. {
  18125. tempIndex = gun_index;
  18126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18127. {
  18128. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18129. {
  18130. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18131. }
  18132. }
  18133. }
  18134. else
  18135. {
  18136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18137. {
  18138. tempIndex = 2;
  18139. }
  18140. else
  18141. {
  18142. tempIndex = gun_index;
  18143. }
  18144. for (int index = 0; index < AC_QUANTITY; index++)
  18145. {
  18146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18147. {
  18148. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18149. }
  18150. }// END OF AC_QUANTITY
  18151. }
  18152. //Stop Transaction Time
  18153. struct timeval tmnow;
  18154. struct tm *tm;
  18155. char buf[28];//, usec_buf[6];
  18156. gettimeofday(&tmnow, NULL);
  18157. time_t t;
  18158. t = time(NULL);
  18159. /*UTC time and date*/
  18160. tm = gmtime(&t);
  18161. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18163. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18165. random_uuid(guid);
  18166. /***********************************transactionData******************************************************/
  18167. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18169. //=================================
  18170. //1. Transaction_Begin
  18171. //=================================
  18172. //============================== Energy.Active.Import.Interval ===========================================
  18173. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18174. {
  18175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  18176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  18178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  18179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18180. 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))
  18181. {
  18182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  18183. }
  18184. else
  18185. {
  18186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  18187. }
  18188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  18189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18190. }
  18191. //=================================
  18192. //2. Transaction_End
  18193. //=================================
  18194. //2.1====================================== Current.Import L1 ==============================================
  18195. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18196. {
  18197. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18199. {
  18200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18201. {
  18202. tempIndex = ((gun_index==2) ? 1: 0);
  18203. }
  18204. else
  18205. {
  18206. tempIndex = gun_index;
  18207. }
  18208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18209. {
  18210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18211. {
  18212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18213. }
  18214. }// End of for CHAdeMO_QUANTITY
  18215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18216. }
  18217. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18218. {
  18219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18220. {
  18221. tempIndex = ((gun_index==2) ? 1: 0);
  18222. }
  18223. else
  18224. {
  18225. tempIndex = gun_index;
  18226. }
  18227. for (int index = 0; index < CCS_QUANTITY; index++)
  18228. {
  18229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18230. {
  18231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18232. }
  18233. }// End of for CCS_QUANTITY
  18234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18235. }
  18236. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18237. {
  18238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18239. {
  18240. tempIndex = ((gun_index==2) ? 1: 0);
  18241. }
  18242. else
  18243. {
  18244. tempIndex = gun_index;
  18245. }
  18246. for (int index = 0; index < GB_QUANTITY; index++)
  18247. {
  18248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18249. {
  18250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18251. }
  18252. }// End of for GB_QUANTITY
  18253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18254. }
  18255. else if(gunType[gun_index] == GUN_TYPE_DO)
  18256. {
  18257. tempIndex = gun_index;
  18258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18259. {
  18260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18261. {
  18262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18263. }
  18264. }
  18265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18266. }
  18267. else
  18268. {
  18269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18270. {
  18271. tempIndex = 2;
  18272. }
  18273. else
  18274. {
  18275. tempIndex = gun_index;
  18276. }
  18277. for (int index = 0; index < AC_QUANTITY; index++)
  18278. {
  18279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18280. {
  18281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18282. }
  18283. }// End of for AC_QUANTITY
  18284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18285. }
  18286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18289. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18292. }
  18293. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18294. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18295. {
  18296. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18298. {
  18299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18300. {
  18301. tempIndex = ((gun_index==2) ? 1: 0);
  18302. }
  18303. else
  18304. {
  18305. tempIndex = gun_index;
  18306. }
  18307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18308. {
  18309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18310. {
  18311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18312. }
  18313. }// END OF CHAdeMO_QUANTITY
  18314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18315. }
  18316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18317. {
  18318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18319. {
  18320. tempIndex = ((gun_index==2) ? 1: 0);
  18321. }
  18322. else
  18323. {
  18324. tempIndex = gun_index;
  18325. }
  18326. for (int index = 0; index < CCS_QUANTITY; index++)
  18327. {
  18328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18329. {
  18330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18331. }
  18332. }// END OF CCS_QUANTITY
  18333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18334. }
  18335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18336. {
  18337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18338. {
  18339. tempIndex = ((gun_index==2) ? 1: 0);
  18340. }
  18341. else
  18342. {
  18343. tempIndex = gun_index;
  18344. }
  18345. for (int index = 0; index < GB_QUANTITY; index++)
  18346. {
  18347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18348. {
  18349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18350. }
  18351. }// END OF GB_QUANTITY
  18352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18353. }
  18354. else if(gunType[gun_index] == GUN_TYPE_DO)
  18355. {
  18356. tempIndex = gun_index;
  18357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18358. {
  18359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18360. {
  18361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18362. }
  18363. }
  18364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18365. }
  18366. else
  18367. {
  18368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18369. {
  18370. tempIndex = 2;
  18371. }
  18372. else
  18373. {
  18374. tempIndex = gun_index;
  18375. }
  18376. for (int index = 0; index < AC_QUANTITY; index++)
  18377. {
  18378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18379. {
  18380. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18381. }
  18382. }// END OF AC_QUANTITY
  18383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18384. }
  18385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18388. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18391. }
  18392. //2.3====================================== Power.Active.Import =========================================
  18393. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18394. {
  18395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18396. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18397. {
  18398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18399. {
  18400. tempIndex = ((gun_index==2) ? 1: 0);
  18401. }
  18402. else
  18403. {
  18404. tempIndex = gun_index;
  18405. }
  18406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18407. {
  18408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18409. {
  18410. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18411. }
  18412. } // End for CHAdeMO_QUANTITY
  18413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18414. }
  18415. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18416. {
  18417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18418. {
  18419. tempIndex = ((gun_index==2) ? 1: 0);
  18420. }
  18421. else
  18422. {
  18423. tempIndex = gun_index;
  18424. }
  18425. for (int index = 0; index < CCS_QUANTITY; index++)
  18426. {
  18427. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18428. {
  18429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18430. }
  18431. } // END for CCS_QUANTITY
  18432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18433. }
  18434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18435. {
  18436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18437. {
  18438. tempIndex = ((gun_index==2) ? 1: 0);
  18439. }
  18440. else
  18441. {
  18442. tempIndex = gun_index;
  18443. }
  18444. for (int index = 0; index < GB_QUANTITY; index++)
  18445. {
  18446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18447. {
  18448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18449. }
  18450. }// END for GB_QUANTITY
  18451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18452. }
  18453. else if(gunType[gun_index] == GUN_TYPE_DO)
  18454. {
  18455. tempIndex = gun_index;
  18456. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18457. {
  18458. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18459. {
  18460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18461. }
  18462. }
  18463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18464. }
  18465. else
  18466. {
  18467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18468. {
  18469. tempIndex = 2;
  18470. }
  18471. else
  18472. {
  18473. tempIndex = gun_index;
  18474. }
  18475. for (int index = 0; index < AC_QUANTITY; index++)
  18476. {
  18477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18478. {
  18479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18480. }
  18481. } // END for AC_QUANTITY
  18482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18483. }
  18484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18487. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18490. }
  18491. //2.4====================================== Voltage L1 ====================================================
  18492. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18493. {
  18494. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18495. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18496. {
  18497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18498. {
  18499. tempIndex = ((gun_index==2) ? 1: 0);
  18500. }
  18501. else
  18502. {
  18503. tempIndex = gun_index;
  18504. }
  18505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18506. {
  18507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18508. {
  18509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18510. }
  18511. } // END OF FOR CHAdeMO_QUANTITY
  18512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18513. }
  18514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18515. {
  18516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18517. {
  18518. tempIndex = ((gun_index==2) ? 1: 0);
  18519. }
  18520. else
  18521. {
  18522. tempIndex = gun_index;
  18523. }
  18524. for (int index = 0; index < CCS_QUANTITY; index++)
  18525. {
  18526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18527. {
  18528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18529. }
  18530. } // END OF FOR CCS_QUANTITY
  18531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18532. }
  18533. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18534. {
  18535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18536. {
  18537. tempIndex = ((gun_index==2) ? 1: 0);
  18538. }
  18539. else
  18540. {
  18541. tempIndex = gun_index;
  18542. }
  18543. for (int index = 0; index < GB_QUANTITY; index++)
  18544. {
  18545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18546. {
  18547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18548. }
  18549. } // END OF FOR GB_QUANTITY
  18550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18551. }
  18552. else if(gunType[gun_index] == GUN_TYPE_DO)
  18553. {
  18554. tempIndex = gun_index;
  18555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18556. {
  18557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18558. {
  18559. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18560. }
  18561. }
  18562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18563. }
  18564. else
  18565. {
  18566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18567. {
  18568. tempIndex = 2;
  18569. }
  18570. else
  18571. {
  18572. tempIndex = gun_index;
  18573. }
  18574. for (int index = 0; index < AC_QUANTITY; index++)
  18575. {
  18576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18577. {
  18578. 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
  18579. }
  18580. } // END OF FOR AC_QUANTITY
  18581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18582. }
  18583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18586. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18589. }
  18590. //2.5============================================== End SoC =========================================================
  18591. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18592. {
  18593. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18594. 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))
  18595. {
  18596. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18597. {
  18598. tempIndex = ((gun_index==2) ? 1: 0);
  18599. }
  18600. else
  18601. {
  18602. tempIndex = gun_index;
  18603. }
  18604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18605. {
  18606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18607. {
  18608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18609. {
  18610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18611. }
  18612. }
  18613. }
  18614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18615. {
  18616. for (int index = 0; index < CCS_QUANTITY; index++)
  18617. {
  18618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18619. {
  18620. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18621. }
  18622. }
  18623. }
  18624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18625. {
  18626. for (int index = 0; index < GB_QUANTITY; index++)
  18627. {
  18628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18629. {
  18630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18631. }
  18632. }
  18633. }
  18634. else if(gunType[gun_index] == GUN_TYPE_DO)
  18635. {
  18636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18637. {
  18638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18639. {
  18640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18641. }
  18642. }
  18643. }
  18644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18650. } // END FOR DC CASE
  18651. }
  18652. //2.6====================================== Current.Import L2 ==============================================
  18653. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18654. {
  18655. // AC 3 phase L2 current
  18656. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18657. {
  18658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18659. {
  18660. tempIndex = 2;
  18661. }
  18662. else
  18663. {
  18664. tempIndex = gun_index;
  18665. }
  18666. for (int index = 0; index < AC_QUANTITY; index++)
  18667. {
  18668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18669. {
  18670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18671. }
  18672. }// End of for AC_QUANTITY
  18673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18674. }
  18675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18680. }
  18681. //2.7====================================== Current.Import L3 ==============================================
  18682. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18683. {
  18684. // AC 3 phase L3 current
  18685. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18686. {
  18687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18688. {
  18689. tempIndex = 2;
  18690. }
  18691. else
  18692. {
  18693. tempIndex = gun_index;
  18694. }
  18695. for (int index = 0; index < AC_QUANTITY; index++)
  18696. {
  18697. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18698. {
  18699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18700. }
  18701. }// End of for AC_QUANTITY
  18702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18703. }
  18704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18709. }
  18710. //2.9====================================== Voltage L2 ====================================================
  18711. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18712. {
  18713. // AC 3 phase L2 volatge
  18714. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18715. {
  18716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18717. {
  18718. tempIndex = 2;
  18719. }
  18720. else
  18721. {
  18722. tempIndex = gun_index;
  18723. }
  18724. for (int index = 0; index < AC_QUANTITY; index++)
  18725. {
  18726. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18727. {
  18728. 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
  18729. }
  18730. } // END OF FOR AC_QUANTITY
  18731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18732. }
  18733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18738. }
  18739. //2.10====================================== Voltage L3 ====================================================
  18740. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18741. {
  18742. // AC 3 phase L3 volatge
  18743. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18744. {
  18745. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18746. {
  18747. tempIndex = 2;
  18748. }
  18749. else
  18750. {
  18751. tempIndex = gun_index;
  18752. }
  18753. for (int index = 0; index < AC_QUANTITY; index++)
  18754. {
  18755. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18756. {
  18757. 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
  18758. }
  18759. } // END OF FOR AC_QUANTITY
  18760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18761. }
  18762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18767. }
  18768. //====================== Start SoC ================================
  18769. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18770. {
  18771. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18772. 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))
  18773. {
  18774. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18775. {
  18776. tempIndex = ((gun_index==2) ? 1: 0);
  18777. }
  18778. else
  18779. {
  18780. tempIndex = gun_index;
  18781. }
  18782. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18783. {
  18784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18785. {
  18786. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18787. {
  18788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18789. }
  18790. }
  18791. }
  18792. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18793. {
  18794. for (int index = 0; index < CCS_QUANTITY; index++)
  18795. {
  18796. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18797. {
  18798. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18799. }
  18800. }
  18801. }
  18802. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18803. {
  18804. for (int index = 0; index < GB_QUANTITY; index++)
  18805. {
  18806. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18807. {
  18808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18809. }
  18810. }
  18811. }
  18812. else if(gunType[gun_index] == GUN_TYPE_DO)
  18813. {
  18814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18815. {
  18816. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18817. {
  18818. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18819. }
  18820. }
  18821. }
  18822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18828. } // END FOR DC CASE
  18829. }
  18830. //======================================== Message create ==============================================
  18831. json_object *StopTransaction = json_object_new_object();
  18832. json_object *transactionDatas = json_object_new_array();
  18833. json_object *sampledValues = json_object_new_array();
  18834. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18835. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18836. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18837. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18838. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18839. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18840. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18841. {
  18842. json_object *transactionData = json_object_new_object();
  18843. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18844. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18845. {
  18846. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18847. {
  18848. json_object *sampledValue = json_object_new_object();
  18849. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18850. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18851. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18852. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18853. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18854. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18855. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18856. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18857. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18858. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18859. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18860. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18861. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18862. json_object_array_add(sampledValues, sampledValue);
  18863. }
  18864. }
  18865. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18866. json_object_array_add(transactionDatas, transactionData);
  18867. }
  18868. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18869. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18870. ,MESSAGE_TYPE_CALL
  18871. ,guid
  18872. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18873. json_object_put(StopTransaction);
  18874. // Check File "TempStopTransaction" Exist
  18875. if((access(TempStopTransaction,F_OK))!=-1)
  18876. {
  18877. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18878. fclose(fopen(TempStopTransaction, "w"));
  18879. }
  18880. else
  18881. {
  18882. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18883. FILE *log = fopen(TempStopTransaction, "w+");
  18884. if(log == NULL)
  18885. {
  18886. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18887. return ;
  18888. }
  18889. else
  18890. {
  18891. fclose(log);
  18892. }
  18893. }
  18894. //Add TempStopTransaction | Update TempStopTransaction
  18895. // open file for writing
  18896. FILE *outfile;
  18897. outfile = fopen (TempStopTransaction, "a");
  18898. //DEBUG_INFO("data = %s\n", queuedata);
  18899. fputs(queuedata, outfile);
  18900. fputs("\n", outfile);
  18901. fclose (outfile);
  18902. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18903. OCPP_updatePeriodEnergy(gun_index);
  18904. }
  18905. void checkTempStopTransaction(int gun_index)
  18906. {
  18907. FILE *fptr1;
  18908. char ch;
  18909. char str[QUEUE_MESSAGE_LENGTH]={0};
  18910. char guid[37]={0};
  18911. char tempdata[65]={0};
  18912. char connectorStr[2]={0};
  18913. char TempStopTransaction[256];
  18914. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18915. fptr1 = fopen(TempStopTransaction, "r");
  18916. //TempStopTransaction格式: 槍號,StopTransaction封包
  18917. if (!fptr1)
  18918. {
  18919. //printf(" File not found or unable to open the input file!!\n");
  18920. return ;
  18921. }
  18922. ch=fgetc(fptr1);
  18923. //printf(" Now the content of the file %s is : \n",fname);
  18924. rewind(fptr1);
  18925. if(ch!=EOF)
  18926. {
  18927. // copy all contents to the temporary file except the specific line
  18928. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18929. {
  18930. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18931. if(str[0]=='\0')
  18932. {
  18933. break;
  18934. }
  18935. //TempStopTransaction格式: 槍號,StopTransaction封包
  18936. strncpy(connectorStr, str, 1);
  18937. if(atoi(connectorStr) != (gun_index+1))
  18938. {
  18939. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18940. fclose(fptr1);
  18941. return ;
  18942. }
  18943. //random_uuid(guid);
  18944. strncpy(guid, str+6, 36); //copy guid
  18945. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18946. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18947. {
  18948. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18949. }
  18950. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18951. OCPP_insert_transaction_msg(NO, str);
  18952. memset(str,0,ARRAY_SIZE(str));
  18953. }
  18954. }
  18955. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18956. fclose(fptr1);
  18957. remove(TempStopTransaction); // remove the original file
  18958. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18959. }
  18960. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18961. {
  18962. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18963. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18964. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18965. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18966. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18967. }
  18968. int GetWebSocketPingInterval(void)
  18969. {
  18970. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18971. }
  18972. int GetServerSign(void)
  18973. {
  18974. return server_sign;
  18975. }
  18976. uint8_t GetOcppSecurityProfile()
  18977. {
  18978. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18979. }
  18980. void GetOcppChargerBoxId(uint8_t *data)
  18981. {
  18982. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18983. }
  18984. void GetOcppSecurityPassword(uint8_t *data)
  18985. {
  18986. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18987. }
  18988. void SetOcppVersion(uint8_t *version)
  18989. {
  18990. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18991. DEBUG_INFO("ocpp version: %s\n", version);
  18992. if(strstr((char*)version, "ocpp1.6") != NULL)
  18993. {
  18994. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18995. }
  18996. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18997. {
  18998. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18999. system("pkill OcppBackend");
  19000. }
  19001. }
  19002. void SetServerSign(int value)
  19003. {
  19004. server_sign = value;
  19005. }
  19006. int GetBootNotificationInterval(void)
  19007. {
  19008. return BootNotificationInterval;
  19009. }
  19010. int GetInternetConn(void)
  19011. {
  19012. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19013. }
  19014. int GetBackendConnectionTimeout(void)
  19015. {
  19016. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19017. }
  19018. int isConnectorInitMode(int gun_index)
  19019. {
  19020. int tempIndex = 0;
  19021. int result = TRUE;
  19022. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19023. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19024. {
  19025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19026. {
  19027. tempIndex = ((gun_index==2) ? 1: 0);
  19028. }
  19029. else
  19030. {
  19031. tempIndex = gun_index;
  19032. }
  19033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19034. {
  19035. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19036. {
  19037. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19038. } //end of the same index
  19039. }//end of for CHAdeMO_QUANTITY
  19040. }
  19041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19042. {
  19043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19044. {
  19045. tempIndex = ((gun_index==2) ? 1: 0);
  19046. }
  19047. else
  19048. {
  19049. tempIndex = gun_index;
  19050. }
  19051. for (int index = 0; index < CCS_QUANTITY; index++)
  19052. {
  19053. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19054. {
  19055. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19056. } //end of the same index
  19057. } // end of for CCS_QUANTITY
  19058. }
  19059. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19060. {
  19061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19062. {
  19063. tempIndex = ((gun_index==2) ? 1: 0);
  19064. }
  19065. else
  19066. {
  19067. tempIndex = gun_index;
  19068. }
  19069. for (int index = 0; index < GB_QUANTITY; index++)
  19070. {
  19071. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19072. {
  19073. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19074. } //end of the same index
  19075. } // end of for GB_QUANTITY
  19076. }
  19077. else if(gunType[gun_index] == GUN_TYPE_DO)
  19078. {
  19079. tempIndex = gun_index;
  19080. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19081. {
  19082. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19083. {
  19084. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19085. } //end of the same index
  19086. }
  19087. }
  19088. else
  19089. {
  19090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19091. {
  19092. tempIndex = 2;
  19093. }
  19094. else
  19095. {
  19096. tempIndex = gun_index;
  19097. }
  19098. for (int index = 0; index < AC_QUANTITY; index++)
  19099. {
  19100. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19101. {
  19102. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19103. }//end of the same index
  19104. }//end of for AC_QUANTITY
  19105. }
  19106. return result;
  19107. }
  19108. void refreshProcDogTimer()
  19109. {
  19110. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19111. }
  19112. void InitialSystemValue(void)
  19113. {
  19114. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19115. locallistVersion=0;
  19116. BootNotificationInterval = 0;
  19117. authorizeRetryTimes = 0;
  19118. GunStatusInterval = 10;
  19119. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19120. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19121. //Hear Beat
  19122. HeartBeatWithNOResponse = 0;
  19123. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19124. FirstHeartBeat = 0;
  19125. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19126. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19127. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19128. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19129. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19130. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19131. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19132. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19133. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19134. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19135. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19136. //Status && ConnectorPlugIn Setting
  19137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19138. {
  19139. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19140. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19141. }
  19142. for (int index = 0; index < CCS_QUANTITY; index++)
  19143. {
  19144. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19145. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19146. }
  19147. for (int index = 0; index < GB_QUANTITY; index++)
  19148. {
  19149. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19150. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19151. }
  19152. for (int index = 0; index < AC_QUANTITY; index++)
  19153. {
  19154. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19155. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19156. }
  19157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19158. {
  19159. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19160. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19161. }
  19162. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19163. {
  19164. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19165. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19166. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19167. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19168. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19169. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19170. }
  19171. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19172. refreshStartTimer(&clientTime.Heartbeat);
  19173. sleep(1);
  19174. }
  19175. void LWS_Send(char *str)
  19176. {
  19177. //=====================================================
  19178. // Check InternetConn 0: disconnected, 1: connected
  19179. //====================================================
  19180. if(GetOcppConnStatus() == 0)
  19181. {
  19182. DEBUG_INFO("offline now !!!\n");
  19183. return;
  19184. }
  19185. // Only disable isWebsocketSendable operation initiated by charger
  19186. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19187. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19188. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19189. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19190. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19191. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19192. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19193. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19194. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19195. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19196. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19197. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19198. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19199. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19200. {
  19201. isWebsocketSendable = 0;
  19202. }
  19203. pthread_mutex_lock(&lock_send);
  19204. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19205. sprintf((char *)SendBuffer, "%s", str);
  19206. SendBufLen = strlen(str);
  19207. pthread_mutex_unlock(&lock_send);
  19208. lws_callback_on_writable(wsi_client);
  19209. //lws_service(context, 0);
  19210. //sleep(1);
  19211. }
  19212. void LWS_SendNow(char *str)
  19213. {
  19214. //=====================================================
  19215. // Check InternetConn 0: disconnected, 1: connected
  19216. //====================================================
  19217. if(GetOcppConnStatus() == 0)
  19218. {
  19219. DEBUG_INFO("offline now !!!\n");
  19220. return;
  19221. }
  19222. // Only disable isWebsocketSendable operation initiated by charger
  19223. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19224. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19225. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19226. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19227. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19228. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19229. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19230. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19231. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19232. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19233. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19234. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19235. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19236. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19237. {
  19238. isWebsocketSendable = 0;
  19239. }
  19240. pthread_mutex_lock(&lock_send);
  19241. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19242. sprintf((char *)SendBuffer, "%s", str);
  19243. SendBufLen = strlen(str);
  19244. pthread_mutex_unlock(&lock_send);
  19245. lws_callback_on_writable(wsi_client);
  19246. lws_service(context, 0);
  19247. //sleep(1);
  19248. }