MessageHandler.c 911 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791
  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. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  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. }clientTime;
  110. typedef union
  111. {
  112. //Operations Initiated by Central System
  113. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  114. struct
  115. {
  116. //CsMsgValue[0]
  117. unsigned char StatusNotificationReq:1; //bit 0,
  118. unsigned char StatusNotificationConf:1; //bit 1,
  119. unsigned char TriggerMeterValue:1; //bit 2,
  120. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  121. unsigned char isOnCharging:1; //bit 4,
  122. unsigned char :3; //bit5~7
  123. }bits[CONNECTOR_QUANTITY];
  124. }CpinitiateMsg;
  125. CpinitiateMsg cpinitateMsg;
  126. //GetConfiguration Array
  127. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  128. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  130. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  131. #if 0
  132. static char *ChargePointErrorCodeStr[] = {
  133. MACROSTR(ConnectorLockFailure),
  134. MACROSTR(EVCommunicationError),
  135. MACROSTR(GroundFailure),
  136. MACROSTR(HighTemperature),
  137. MACROSTR(InternalError),
  138. MACROSTR(LocalListConflict),
  139. MACROSTR(NoError),
  140. MACROSTR(OtherError),
  141. MACROSTR(OverCurrentFailure),
  142. MACROSTR(OverVoltage),
  143. MACROSTR(PowerMeterFailure),
  144. MACROSTR(PowerSwitchFailure),
  145. MACROSTR(ReaderFailure),
  146. MACROSTR(ResetFailure),
  147. MACROSTR(UnderVoltage),
  148. MACROSTR(WeakSignal)
  149. };
  150. #endif
  151. static char * ChargePointStatusStr[] = {
  152. MACROSTR(Available),
  153. MACROSTR(Preparing),
  154. MACROSTR(Charging),
  155. MACROSTR(SuspendedEVSE),
  156. MACROSTR(SuspendedEV),
  157. MACROSTR(Finishing),
  158. MACROSTR(Reserved),
  159. MACROSTR(Unavailable),
  160. MACROSTR(Faulted)
  161. };
  162. static char *RegistrationStatusStr[] = {
  163. MACROSTR(Accepted),
  164. MACROSTR(Pending),
  165. MACROSTR(Rejected)
  166. };
  167. static char *AvailabilityTypeStr[] = {
  168. MACROSTR(Inoperative),
  169. MACROSTR(Operative)
  170. };
  171. static char *AvailabilityStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(Scheduled)
  175. };
  176. static char *ConfigurationStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected),
  179. MACROSTR(RebootRequired),
  180. MACROSTR(NotSupported)
  181. };
  182. static char *ClearCacheStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected)
  185. };
  186. static char *ChargingProfilePurposeTypeStr[] = {
  187. MACROSTR(ChargePointMaxProfile),
  188. MACROSTR(TxDefaultProfile),
  189. MACROSTR(TxProfile)
  190. };
  191. static char *ChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Rejected),
  194. MACROSTR(NotSupported)
  195. };
  196. static char *ClearChargingProfileStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Unknown)
  199. };
  200. static char *GetCompositeScheduleStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Rejected)
  203. };
  204. static char *UpdateTypeStr[] = {
  205. MACROSTR(Differential),
  206. MACROSTR(Full)
  207. };
  208. static char *UpdateStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotSupported),
  212. MACROSTR(VersionMismatch)
  213. };
  214. static char *RemoteStartStopStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Rejected)
  217. };
  218. static char *ReservationStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Faulted),
  221. MACROSTR(Occupied),
  222. MACROSTR(Rejected),
  223. MACROSTR(Unavailable)
  224. };
  225. static char *ResetTypeStr[] = {
  226. MACROSTR(Hard),
  227. MACROSTR(Soft)
  228. };
  229. static char *ResetStatusStr[] = {
  230. MACROSTR(Accepted),
  231. MACROSTR(Rejected)
  232. };
  233. static char * DiagnosticsStatusStr[] = {
  234. MACROSTR(Idle),
  235. MACROSTR(Uploaded),
  236. MACROSTR(UploadFailed),
  237. MACROSTR(Uploading)
  238. };
  239. static char * FirmwareStatusStr[] = {
  240. MACROSTR(Downloaded),
  241. MACROSTR(DownloadFailed),
  242. MACROSTR(Downloading),
  243. MACROSTR(Idle),
  244. MACROSTR(InstallationFailed),
  245. MACROSTR(Installing),
  246. MACROSTR(Installed)
  247. };
  248. static char * MessageTriggerStr[] = {
  249. MACROSTR(BootNotification),
  250. MACROSTR(DiagnosticsStatusNotification),
  251. MACROSTR(FirmwareStatusNotification),
  252. MACROSTR(Heartbeat),
  253. MACROSTR(MeterValues),
  254. MACROSTR(StatusNotification)
  255. };
  256. static char * TriggerMessageStatusStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotImplemented)
  260. };
  261. static char * UnlockStatusStr[] = {
  262. MACROSTR(Unlocked),
  263. MACROSTR(UnlockFailed),
  264. MACROSTR(NotSupported)
  265. };
  266. #if 0
  267. static char * StopTransactionReasonStr[] = {
  268. MACROSTR(EmergencyStop),
  269. MACROSTR(EVDisconnected),
  270. MACROSTR(HardReset),
  271. MACROSTR(Local),
  272. MACROSTR(Other),
  273. MACROSTR(PowerLoss),
  274. MACROSTR(Reboot),
  275. MACROSTR(Remote),
  276. MACROSTR(SoftReset),
  277. MACROSTR(UnlockCommand),
  278. MACROSTR(DeAuthorized)
  279. };
  280. #endif
  281. static char * CancelReservationStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Rejected)
  284. };
  285. static char * ReadingContextStr[] = {
  286. MACROSTR(Interruption.Begin),
  287. MACROSTR(Interruption.End),
  288. MACROSTR(Other),
  289. MACROSTR(Sample.Clock),
  290. MACROSTR(Sample.Periodic),
  291. MACROSTR(Transaction.Begin),
  292. MACROSTR(Transaction.End),
  293. MACROSTR(Trigger)
  294. };
  295. static char * ValueFormatStr[] = {
  296. MACROSTR(Raw),
  297. MACROSTR(SignedData)
  298. };
  299. static char * MeasurandStr[] = {
  300. MACROSTR(Current.Export),
  301. MACROSTR(Current.Import),
  302. MACROSTR(Current.Offered),
  303. MACROSTR(Energy.Active.Export.Register),
  304. MACROSTR(Energy.Active.Import.Register),
  305. MACROSTR(Energy.Reactive.Export.Register),
  306. MACROSTR(Energy.Reactive.Import.Register),
  307. MACROSTR(Energy.Active.Export.Interval),
  308. MACROSTR(Energy.Active.Import.Interval),
  309. MACROSTR(Energy.Reactive.Export.Interval),
  310. MACROSTR(Energy.Reactive.Import.Interval),
  311. MACROSTR(Frequency),
  312. MACROSTR(Power.Active.Export),
  313. MACROSTR(Power.Active.Import),
  314. MACROSTR(Power.Factor),
  315. MACROSTR(Power.Offered),
  316. MACROSTR(Power.Reactive.ExportMACROSTR),
  317. MACROSTR(Power.Reactive.Import),
  318. MACROSTR(RPM),
  319. MACROSTR(SoC),
  320. MACROSTR(Temperature),
  321. MACROSTR(Voltage)
  322. };
  323. static char * LocationStr[] = {
  324. MACROSTR(Body),
  325. MACROSTR(Cable),
  326. MACROSTR(EV),
  327. MACROSTR(Inlet),
  328. MACROSTR(Outlet)
  329. };
  330. static char * PhaseStr[] = {
  331. MACROSTR(L1),
  332. MACROSTR(L2),
  333. MACROSTR(L3),
  334. MACROSTR(N),
  335. MACROSTR(L1-N),
  336. MACROSTR(L2-N),
  337. MACROSTR(L3-N),
  338. MACROSTR(L1-L2),
  339. MACROSTR(L2-L3),
  340. MACROSTR(L3-L1)
  341. };
  342. static char * UnitOfMeasureStr[] = {
  343. MACROSTR(Wh),
  344. MACROSTR(kWh),
  345. MACROSTR(varh),
  346. MACROSTR(kvarh),
  347. MACROSTR(W),
  348. MACROSTR(kW),
  349. MACROSTR(VA),
  350. MACROSTR(kVA),
  351. MACROSTR(var),
  352. MACROSTR(kvar),
  353. MACROSTR(A),
  354. MACROSTR(V),
  355. MACROSTR(Celsius),
  356. MACROSTR(Fahrenheit),
  357. MACROSTR(K),
  358. MACROSTR(Percent)
  359. };
  360. //=========================================
  361. // TTIA routine
  362. //=========================================
  363. int sendTTIAInfo(uint8_t gun_index)
  364. {
  365. static int sn = 0;
  366. int result = FAIL;
  367. struct hostent *server;
  368. int udp_socket_fd;
  369. struct sockaddr_in dest_addr = {0};
  370. uint8_t tx_buf[80] = {0};
  371. uint8_t logBuf[256]= {0};
  372. uint8_t tx_len, tempIndex, socStart, socEnd;
  373. uint16_t PresentChargedEnergy;
  374. struct tm tmStart, tmEnd;
  375. DEBUG_INFO("sendTTIAInfo...\n");
  376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  377. {
  378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  379. {
  380. tempIndex = ((gun_index==2) ? 1: 0);
  381. }
  382. else
  383. {
  384. tempIndex = gun_index;
  385. }
  386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  387. {
  388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  389. {
  390. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  391. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  392. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  393. }
  394. }
  395. }
  396. else if(gunType[gun_index] == GUN_TYPE_CCS)
  397. {
  398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  399. {
  400. tempIndex = ((gun_index==2) ? 1: 0);
  401. }
  402. else
  403. {
  404. tempIndex = gun_index;
  405. }
  406. for (int index = 0; index < CCS_QUANTITY; index++)
  407. {
  408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  409. {
  410. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  411. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  412. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  413. }
  414. }
  415. }
  416. else if(gunType[gun_index] == GUN_TYPE_GBT)
  417. {
  418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  419. {
  420. tempIndex = ((gun_index==2) ? 1: 0);
  421. }
  422. else
  423. {
  424. tempIndex = gun_index;
  425. }
  426. for (int index = 0; index < GB_QUANTITY; index++)
  427. {
  428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  429. {
  430. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  431. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  432. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  433. }
  434. }
  435. }
  436. else if(gunType[gun_index] == GUN_TYPE_DO)
  437. {
  438. tempIndex = gun_index;
  439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  440. {
  441. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  442. {
  443. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  444. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  445. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  446. }
  447. }
  448. }
  449. else
  450. {
  451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  452. {
  453. tempIndex = 2;
  454. }
  455. else
  456. {
  457. tempIndex = gun_index;
  458. }
  459. for (int index = 0; index < AC_QUANTITY; index++)
  460. {
  461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  462. {
  463. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  464. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  465. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  466. }
  467. }// END
  468. }
  469. // Message assembly
  470. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  471. tx_buf[4] = 0x02; // Protocol Version
  472. tx_buf[5] = 0xb0; // Message ID
  473. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  474. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  475. tx_buf[8] = 0x00; // CarID low byte
  476. tx_buf[9] = 0x00; // CarID high byte
  477. tx_buf[10] = 0x00; // ID Storage
  478. tx_buf[11] = 0x00; // Driver lowest byte
  479. tx_buf[12] = 0x00; // Driver 2nd byte
  480. tx_buf[13] = 0x00; // Driver 3rd byte
  481. tx_buf[14] = 0x00; // Driver highest byte
  482. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  483. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  484. tx_buf[17] = 0x00; // Reserve
  485. tx_buf[18] = 60 & 0xff; // Payload length low byte
  486. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  487. // EVSE provider
  488. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  489. // EVSE provider
  490. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  491. // EVSE id
  492. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  493. // Connector id
  494. tx_buf[37] = gun_index;
  495. // EVSE station
  496. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  497. // Vehicle SN
  498. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  499. // Mileage
  500. tx_buf[61] = 0x00; // lowest byte
  501. tx_buf[62] = 0x00; // 2nd byte
  502. tx_buf[63] = 0x00; // highest byte
  503. // Start date time 6 bytes
  504. 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))
  505. {
  506. struct tm *tmTarget;
  507. struct timeb tbTarget;
  508. tmStart.tm_year -= 1900;
  509. tmStart.tm_mon -= 1;
  510. tmStart.tm_gmtoff = 0;
  511. tbTarget.time = mktime(&tmStart);
  512. tbTarget.timezone = 0;
  513. tbTarget.time += (8*3600);
  514. tmTarget = gmtime(&tbTarget.time);
  515. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  516. tx_buf[65] = (tmTarget->tm_mon+1);
  517. tx_buf[66] = tmTarget->tm_mday;
  518. tx_buf[67] = tmTarget->tm_hour;
  519. tx_buf[68] = tmTarget->tm_min;
  520. tx_buf[69] = tmTarget->tm_sec;
  521. }
  522. // Stop date time 6 bytes
  523. 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))
  524. {
  525. struct tm *tmTarget;
  526. struct timeb tbTarget;
  527. tmEnd.tm_year -= 1900;
  528. tmEnd.tm_mon -= 1;
  529. tmEnd.tm_gmtoff = 0;
  530. tbTarget.time = mktime(&tmEnd);
  531. tbTarget.timezone = 0;
  532. tbTarget.time += (8*3600);
  533. tmTarget = gmtime(&tbTarget.time);
  534. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  535. tx_buf[71] = (tmTarget->tm_mon+1);
  536. tx_buf[72] = tmTarget->tm_mday;
  537. tx_buf[73] = tmTarget->tm_hour;
  538. tx_buf[74] = tmTarget->tm_min;
  539. tx_buf[75] = tmTarget->tm_sec;
  540. }
  541. // Session energy 2 bytes
  542. tx_buf[76] = PresentChargedEnergy & 0xff;
  543. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  544. // Start SOC 1 byte
  545. tx_buf[78] = socStart;
  546. // Stop SOC 1 byte
  547. tx_buf[79] = socEnd;
  548. // Open socket
  549. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  550. if(udp_socket_fd == -1)
  551. {
  552. DEBUG_ERROR("UDP socket create failed!\n");
  553. }
  554. else
  555. {
  556. // Get server DNS entry
  557. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  558. if (server == NULL)
  559. {
  560. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  561. }
  562. else
  563. {
  564. // Build the server's Internet address
  565. bzero((char *) &dest_addr, sizeof(dest_addr));
  566. dest_addr.sin_family = AF_INET;
  567. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  568. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  569. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  570. {
  571. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  572. {
  573. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  574. }
  575. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  576. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  577. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  578. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  579. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  580. DEBUG_TTIA_INFO("---------- Header ----------\n");
  581. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  582. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  583. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  584. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  585. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  586. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  587. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  588. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  589. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  590. DEBUG_TTIA_INFO("Len: 0x3C\n");
  591. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  592. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  593. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  594. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  595. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  596. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  597. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  598. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  599. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  600. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  602. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  603. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  604. DEBUG_TTIA_INFO("=========================================\n");
  605. sn++;
  606. result = PASS;
  607. }
  608. else
  609. {
  610. DEBUG_ERROR("UDP sent out fail.\n");
  611. }
  612. }
  613. }
  614. return result;
  615. }
  616. //=========================================
  617. // Save configuration
  618. //=========================================
  619. int runShellCmd(const char*cmd)
  620. {
  621. int result = FAIL;
  622. char buf[256];
  623. FILE *fp;
  624. fp = popen(cmd, "r");
  625. if(fp != NULL)
  626. {
  627. while(fgets(buf, sizeof(buf), fp) != NULL)
  628. {
  629. DEBUG_INFO("%s\n", buf);
  630. }
  631. result = PASS;
  632. }
  633. pclose(fp);
  634. return result;
  635. }
  636. int StoreUsrConfigData(struct SysConfigData *UsrData)
  637. {
  638. int result = PASS;
  639. int fd,wrd;
  640. unsigned int i,Chk;
  641. unsigned char *ptr, *BufTmp;
  642. int MtdBlockSize = 0x300000;
  643. Chk=0;
  644. ptr=(unsigned char *)UsrData;
  645. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  646. {
  647. memset(BufTmp,0,MtdBlockSize);
  648. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  649. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  650. Chk+=*(BufTmp+i);
  651. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  652. // Output configuration to file.
  653. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  654. if (fd < 0)
  655. {
  656. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  657. free(BufTmp);
  658. return 0;
  659. }
  660. wrd=write(fd, BufTmp, MtdBlockSize);
  661. close(fd);
  662. if(wrd<MtdBlockSize)
  663. {
  664. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  665. free(BufTmp);
  666. return 0;
  667. }
  668. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  669. DEBUG_INFO("Erase /dev/mtd10.\n");
  670. runShellCmd("flash_erase /dev/mtd10 0 0");
  671. DEBUG_INFO("Write /dev/mtd10.\n");
  672. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  673. DEBUG_INFO("Erase /dev/mtd11.\n");
  674. runShellCmd("flash_erase /dev/mtd11 0 0");
  675. DEBUG_INFO("Write /dev/mtd11.\n");
  676. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  677. system("rm -f /mnt/EvseConfig.bin");
  678. DEBUG_INFO("EvseConfig write to flash OK\n");
  679. }
  680. else
  681. {
  682. DEBUG_ERROR("alloc BlockSize NG\r\n");
  683. result = FAIL;
  684. }
  685. if(BufTmp!=NULL)
  686. free(BufTmp);
  687. return result;
  688. }
  689. //=========================================
  690. // Sqlite3 related function
  691. //=========================================
  692. static int selectSqlCount = 0;
  693. static int callback(void *data, int argc, char **argv, char **azColName){
  694. int i;
  695. //printf("%s: ", (const char*)data);
  696. selectSqlCount = argc;
  697. for(i = 0; i<argc; i++){
  698. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  699. }
  700. //printf("\n");
  701. return 0;
  702. }
  703. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  704. //int i;
  705. //printf("%s:\n", (const char*)data);
  706. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  707. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  708. return 0;
  709. }
  710. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  711. //printf("%s:\n", (const char*)data);
  712. //idTag
  713. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  714. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. //parentIdTag
  716. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  717. //expir_date
  718. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  719. //status
  720. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  721. //version
  722. if(columenCount > 5)
  723. idTagQuery.listVersionInt = atoi(columnValue[5]);
  724. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  725. return 0;
  726. }
  727. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  728. {
  729. // localversion = argv[5] ? atoi(argv[5]) : 0;
  730. // printf("localversion=%d\n", localversion);
  731. return 0;
  732. }
  733. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  734. {
  735. for (int i = 0; i < n_columns; i++)
  736. {
  737. DEBUG_INFO("%s\t", col_values[i]);
  738. }
  739. DEBUG_INFO("\n");
  740. return 0;
  741. }
  742. int OCPP_cleanLocalCache()
  743. {
  744. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  745. char *errMsg = 0;
  746. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  747. if (SQLITE_OK != rc)
  748. {
  749. DEBUG_INFO("SQL error: %s\n",errMsg);
  750. return FALSE;
  751. }
  752. return TRUE;
  753. }
  754. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  755. {
  756. int isSuccess = TRUE;
  757. int ret = 0;
  758. //const char* data = "Callback function called";
  759. char sql[300];
  760. char zErrMsg[200];
  761. memset(sql, 0, 300);
  762. memset(zErrMsg, 0, 200);
  763. 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);
  764. //* Execute SQL statement */
  765. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  766. if( ret != SQLITE_OK )
  767. {
  768. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  769. isSuccess = FALSE;
  770. }
  771. return isSuccess;
  772. }
  773. void OCPP_getIdTagFromLocalCache(char idTag[])
  774. {
  775. int rc = 0;
  776. char sql[100];
  777. char zErrMsg[100];
  778. memset(sql, 0, 100);
  779. memset(zErrMsg, 0, 100);
  780. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  781. memset(&idTagQuery, 0, sizeof(idTagQuery));
  782. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  783. /* Execute SQL statement */
  784. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  785. if( rc != SQLITE_OK )
  786. {
  787. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  788. }
  789. }
  790. void OCPP_getListVerion()
  791. {
  792. int rc = 0;
  793. // const char* data = "Callback function called";
  794. char sql[100];
  795. char zErrMsg[100];
  796. memset(sql, 0, 100);
  797. memset(zErrMsg, 0, 100);
  798. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  799. /* Execute SQL statement */
  800. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  801. if( rc != SQLITE_OK )
  802. {
  803. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  804. }
  805. }
  806. void OCPP_get_TableAuthlocalAllData(void)
  807. {
  808. int rc = 0;
  809. char sql[100];
  810. char zErrMsg[100];
  811. memset(sql, 0, 100);
  812. memset(zErrMsg, 0, 100);
  813. sprintf(sql,"select * from ocpp_auth_local ");
  814. /* Execute SQL statement */
  815. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  816. if( rc != SQLITE_OK )
  817. {
  818. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  819. }
  820. //return ver;
  821. }
  822. int OCPP_cleanLocalList()
  823. {
  824. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  825. char *errMsg = 0;
  826. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  827. if (SQLITE_OK != rc)
  828. {
  829. DEBUG_INFO("%s\n",errMsg);
  830. return FALSE;
  831. }
  832. return TRUE;
  833. }
  834. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  835. {
  836. int isSuccess = FALSE;
  837. int ret = 0;
  838. //const char* data = "Callback function called";
  839. char sql[300];
  840. char zErrMsg[200];
  841. memset(sql, 0, 300);
  842. memset(zErrMsg, 0, 200);
  843. 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);
  844. //* Execute SQL statement */
  845. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  846. if( ret != SQLITE_OK )
  847. {
  848. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  849. return isSuccess;
  850. }
  851. memset(sql, 0, 300);
  852. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  853. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  854. if( ret != SQLITE_OK )
  855. {
  856. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  857. return isSuccess;
  858. }
  859. isSuccess = TRUE;
  860. return isSuccess;
  861. }
  862. void OCPP_getIdTagFromLocalList(char idTag[])
  863. {
  864. int rc = 0;
  865. // const char* data = "Callback function called";
  866. char sql[100];
  867. char zErrMsg[100];
  868. memset(sql, 0, 100);
  869. memset(zErrMsg, 0, 100);
  870. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  871. memset(&idTagQuery, 0, sizeof(idTagQuery));
  872. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  873. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  874. /* Execute SQL statement */
  875. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  876. if( rc != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. }
  880. //return ver;
  881. }
  882. void OCPP_deleteIdTagFromLocalList(char idTag[])
  883. {
  884. //int ver = 0;
  885. //int isSuccess = FALSE;
  886. int rc = 0;
  887. char sql[100];
  888. char zErrMsg[100];
  889. memset(sql, 0, 100);
  890. memset(zErrMsg, 0, 100);
  891. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  892. //* Execute SQL statement */
  893. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  894. if( rc != SQLITE_OK )
  895. {
  896. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  897. }
  898. }
  899. int getCurrentYear()
  900. {
  901. int result = 0;
  902. time_t CurrentTime;
  903. struct tm *tm;
  904. CurrentTime = time(NULL);
  905. tm=localtime(&CurrentTime);
  906. result = (tm->tm_year + 1900);
  907. return result;
  908. }
  909. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  910. {
  911. int result = PASS;
  912. char* errMsg = NULL;
  913. char sqlStr[8192];
  914. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  919. }
  920. 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));
  921. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  922. {
  923. result = FAIL;
  924. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  925. }
  926. return result;
  927. }
  928. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  929. {
  930. int isSuccess = TRUE;
  931. int tempIndex;
  932. json_object *EnergyDataTransfer = json_object_new_object();
  933. json_object *periodEnergys = json_object_new_object();
  934. char sql[1024];
  935. char zErrMsg[200];
  936. memset(sql, 0, ARRAY_SIZE(sql));
  937. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  939. {
  940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  941. {
  942. tempIndex = ((gun_index==2) ? 1: 0);
  943. }
  944. else
  945. {
  946. tempIndex = gun_index;
  947. }
  948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  949. {
  950. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  951. {
  952. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  953. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  954. {
  955. uint8_t period[3];
  956. sprintf((char*)period, "%d", idxPeriod);
  957. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  958. }
  959. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  960. } //end of the same index
  961. }//end of for CHAdeMO_QUANTITY
  962. }
  963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  964. {
  965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  966. {
  967. tempIndex = ((gun_index==2) ? 1: 0);
  968. }
  969. else
  970. {
  971. tempIndex = gun_index;
  972. }
  973. for (int index = 0; index < CCS_QUANTITY; index++)
  974. {
  975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  976. {
  977. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  978. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  979. {
  980. uint8_t period[3];
  981. sprintf((char*)period, "%d", idxPeriod);
  982. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  983. }
  984. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  985. } //end of the same index
  986. } // end of for CCS_QUANTITY
  987. }
  988. else if(gunType[gun_index] == GUN_TYPE_GBT)
  989. {
  990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  991. {
  992. tempIndex = ((gun_index==2) ? 1: 0);
  993. }
  994. else
  995. {
  996. tempIndex = gun_index;
  997. }
  998. for (int index = 0; index < GB_QUANTITY; index++)
  999. {
  1000. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1001. {
  1002. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1003. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1004. {
  1005. uint8_t period[3];
  1006. sprintf((char*)period, "%d", idxPeriod);
  1007. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1008. }
  1009. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  1010. } //end of the same index
  1011. } // end of for GB_QUANTITY
  1012. }
  1013. else if(gunType[gun_index] == GUN_TYPE_DO)
  1014. {
  1015. tempIndex = gun_index;
  1016. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1017. {
  1018. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1019. {
  1020. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1021. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1022. {
  1023. uint8_t period[3];
  1024. sprintf((char*)period, "%d", idxPeriod);
  1025. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1026. }
  1027. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  1028. } //end of the same index
  1029. }
  1030. }
  1031. else
  1032. {
  1033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1034. {
  1035. tempIndex = 2;
  1036. }
  1037. else
  1038. {
  1039. tempIndex = gun_index;
  1040. }
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1044. {
  1045. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1046. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1047. {
  1048. uint8_t period[3];
  1049. sprintf((char*)period, "%d", idxPeriod);
  1050. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1051. }
  1052. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1053. }//end of the same index
  1054. }//end of for AC_QUANTITY
  1055. }
  1056. 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));
  1057. json_object_put(EnergyDataTransfer);
  1058. //* Execute SQL statement */
  1059. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1060. {
  1061. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1062. isSuccess = FALSE;
  1063. }
  1064. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1065. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1066. {
  1067. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1068. isSuccess = FALSE;
  1069. }
  1070. return isSuccess;
  1071. }
  1072. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1073. {
  1074. int isSuccess = TRUE;
  1075. char sql[512];
  1076. char zErrMsg[200];
  1077. int rows, cols;
  1078. char **resultData;
  1079. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1080. /* Execute SQL statement */
  1081. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1082. {
  1083. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1084. isSuccess = FALSE;
  1085. }
  1086. else
  1087. {
  1088. if((rows > 0) && (atoi(resultData[4]) > 0))
  1089. {
  1090. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1091. }
  1092. else
  1093. {
  1094. DEBUG_WARN("There is not match transaction data.\n");
  1095. isSuccess = FALSE;
  1096. }
  1097. }
  1098. return isSuccess;
  1099. }
  1100. //==========================================
  1101. // Check time passed since today
  1102. //==========================================
  1103. long long DiffTimebWithNow(struct timeb ST)
  1104. {
  1105. //return milli-second
  1106. struct timeb ET;
  1107. long long StartTime,StopTime;
  1108. ftime(&ET);
  1109. StartTime=(long long)ST.time;
  1110. StopTime=(long long)ET.time;
  1111. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1112. }
  1113. int getTimePassSinceToday(uint8_t gun_index)
  1114. {
  1115. int result = -1;
  1116. static time_t lastTime[4];
  1117. time_t t;
  1118. struct tm *tmStartToday;
  1119. struct timeb tbStartToday;
  1120. t=time(NULL);
  1121. if(difftime(t, lastTime[gun_index])>0)
  1122. {
  1123. tmStartToday=localtime(&t);
  1124. tmStartToday->tm_hour = 0;
  1125. tmStartToday->tm_min = 0;
  1126. tmStartToday->tm_sec = 0;
  1127. tbStartToday.time = mktime(tmStartToday);
  1128. tbStartToday.millitm = 0;
  1129. result = DiffTimebWithNow(tbStartToday)/1000;
  1130. lastTime[gun_index] = t;
  1131. }
  1132. return result;
  1133. }
  1134. void getNowDatetime(uint8_t *data)
  1135. {
  1136. time_t t = time(NULL);
  1137. struct tm tm = *localtime(&t);
  1138. 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);
  1139. }
  1140. int syncDateTimeRTC(uint8_t *data)
  1141. {
  1142. struct ParsingResult
  1143. {
  1144. int result;
  1145. int scanedElement;
  1146. int year;
  1147. int month;
  1148. int mday;
  1149. int hour;
  1150. int min;
  1151. int sec;
  1152. int tz_hour;
  1153. int tz_min;
  1154. float minSec;
  1155. }result;
  1156. struct tm tmOrg;
  1157. struct tm *tmTarget;
  1158. struct timeb tbTarget;
  1159. char buf[128];
  1160. memset(&result, 0x00, sizeof(struct ParsingResult));
  1161. result.result = PASS;
  1162. if(strstr((char*)data, ".") != NULL)
  1163. {
  1164. // Original data with mini second
  1165. if(strstr((char*)data, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1169. &result.year,
  1170. &result.month,
  1171. &result.mday,
  1172. &result.hour,
  1173. &result.min,
  1174. &result.sec,
  1175. &result.minSec);
  1176. }
  1177. else
  1178. {
  1179. // Original data without Z
  1180. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1181. &result.year,
  1182. &result.month,
  1183. &result.mday,
  1184. &result.hour,
  1185. &result.min,
  1186. &result.sec,
  1187. &result.minSec,
  1188. &result.tz_hour,
  1189. &result.tz_min);
  1190. }
  1191. }
  1192. else
  1193. {
  1194. // Original data without mini second
  1195. if(strstr((char*)data, "Z") != NULL)
  1196. {
  1197. // Original data with Z
  1198. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1199. &result.year,
  1200. &result.month,
  1201. &result.mday,
  1202. &result.hour,
  1203. &result.min,
  1204. &result.sec);
  1205. }
  1206. else
  1207. {
  1208. // Original data without Z
  1209. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1210. &result.year,
  1211. &result.month,
  1212. &result.mday,
  1213. &result.hour,
  1214. &result.min,
  1215. &result.sec,
  1216. &result.tz_hour,
  1217. &result.tz_min);
  1218. }
  1219. }
  1220. tmOrg.tm_year = result.year - 1900;
  1221. tmOrg.tm_mon = result.month - 1;
  1222. tmOrg.tm_mday = result.mday;
  1223. tmOrg.tm_hour = result.hour;
  1224. tmOrg.tm_min = result.min;
  1225. tmOrg.tm_sec = result.sec;
  1226. tmOrg.tm_gmtoff = 0;
  1227. tbTarget.time = mktime(&tmOrg);
  1228. tbTarget.timezone = 0;
  1229. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1230. tmTarget = gmtime(&tbTarget.time);
  1231. 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);
  1232. //DEBUG_INFO(" org date time: %s\n", data);
  1233. //DEBUG_INFO("parse date time: %s\n", buf);
  1234. system(buf);
  1235. system("/sbin/hwclock -w --systohc");
  1236. if(result.scanedElement < 6)
  1237. result.result = FAIL;
  1238. return result.result;
  1239. }
  1240. //==========================================
  1241. // GetCompositeSchedule logic related function
  1242. //==========================================
  1243. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1244. {
  1245. //return milli-second
  1246. unsigned int StartTime,StopTime;
  1247. StartTime=(unsigned int)ST.time;
  1248. StopTime=(unsigned int)ET.time;
  1249. return (StopTime-StartTime);
  1250. }
  1251. int DiffTimebWithNowSec(struct timeb ST)
  1252. {
  1253. //return milli-second
  1254. struct timeb ET;
  1255. unsigned int StartTime,StopTime;
  1256. ftime(&ET);
  1257. StartTime=(unsigned int)ST.time;
  1258. StopTime=(unsigned int)ET.time;
  1259. return (StopTime-StartTime);
  1260. }
  1261. int getStartStop(uint8_t *start, uint8_t *stop)
  1262. {
  1263. int result = -1;
  1264. struct tm tmStart;
  1265. struct timeb tbStart;
  1266. struct tm tmStop;
  1267. struct timeb tbStop;
  1268. if((sscanf((char*)start, "%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) &&
  1269. (sscanf((char*)stop, "%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))
  1270. {
  1271. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1272. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1273. tmStart.tm_year -= 1900;
  1274. tmStart.tm_mon -= 1;
  1275. tbStart.time = mktime(&tmStart);
  1276. tbStart.millitm = 0;
  1277. tmStop.tm_year -= 1900;
  1278. tmStop.tm_mon -= 1;
  1279. tbStop.time = mktime(&tmStop);
  1280. tbStop.millitm = 0;
  1281. result = DiffTimebSec(tbStart, tbStop);
  1282. //DEBUG_INFO("getStartStop(): %d\n", result);
  1283. }
  1284. else
  1285. {
  1286. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1287. }
  1288. return result;
  1289. }
  1290. int isOvertNow(uint8_t *start)
  1291. {
  1292. int result = NO;
  1293. struct ParsingResult
  1294. {
  1295. int result;
  1296. int scanedElement;
  1297. int year;
  1298. int month;
  1299. int mday;
  1300. int hour;
  1301. int min;
  1302. int sec;
  1303. int tz_hour;
  1304. int tz_min;
  1305. float minSec;
  1306. }parsingResult;
  1307. struct tm tmStart;
  1308. struct timeb tbStart;
  1309. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1310. if(strstr((char*)start, ".") != NULL)
  1311. {
  1312. // Original data with mini second
  1313. if(strstr((char*)start, "Z") != NULL)
  1314. {
  1315. // Original data with Z
  1316. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1317. &parsingResult.year,
  1318. &parsingResult.month,
  1319. &parsingResult.mday,
  1320. &parsingResult.hour,
  1321. &parsingResult.min,
  1322. &parsingResult.sec,
  1323. &parsingResult.minSec);
  1324. }
  1325. else
  1326. {
  1327. // Original data without Z
  1328. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1329. &parsingResult.year,
  1330. &parsingResult.month,
  1331. &parsingResult.mday,
  1332. &parsingResult.hour,
  1333. &parsingResult.min,
  1334. &parsingResult.sec,
  1335. &parsingResult.minSec,
  1336. &parsingResult.tz_hour,
  1337. &parsingResult.tz_min);
  1338. }
  1339. }
  1340. else
  1341. {
  1342. // Original data without mini second
  1343. if(strstr((char*)start, "Z") != NULL)
  1344. {
  1345. // Original data with Z
  1346. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1347. &parsingResult.year,
  1348. &parsingResult.month,
  1349. &parsingResult.mday,
  1350. &parsingResult.hour,
  1351. &parsingResult.min,
  1352. &parsingResult.sec);
  1353. }
  1354. else
  1355. {
  1356. // Original data without Z
  1357. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1358. &parsingResult.year,
  1359. &parsingResult.month,
  1360. &parsingResult.mday,
  1361. &parsingResult.hour,
  1362. &parsingResult.min,
  1363. &parsingResult.sec,
  1364. &parsingResult.tz_hour,
  1365. &parsingResult.tz_min);
  1366. }
  1367. }
  1368. if(parsingResult.scanedElement >= 6)
  1369. {
  1370. tmStart.tm_year = parsingResult.year - 1900;
  1371. tmStart.tm_mon = parsingResult.month - 1;
  1372. tmStart.tm_mday = parsingResult.mday;
  1373. tmStart.tm_hour = parsingResult.hour;
  1374. tmStart.tm_min = parsingResult.min;
  1375. tmStart.tm_sec = parsingResult.sec;
  1376. tmStart.tm_gmtoff = 0;
  1377. tbStart.time = mktime(&tmStart);
  1378. tbStart.timezone = 0;
  1379. tbStart.millitm = 0;
  1380. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1381. if(DiffTimebWithNowSec(tbStart) <= 0)
  1382. result = NO;
  1383. else
  1384. result = YES;
  1385. }
  1386. else
  1387. {
  1388. DEBUG_WARN("Start date parsing error.\n");
  1389. }
  1390. return result;
  1391. }
  1392. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1393. {
  1394. int result = -1;
  1395. struct tm tmStart;
  1396. struct timeb tbStart;
  1397. struct tm tmStop;
  1398. struct timeb tbStop;
  1399. if((sscanf((char*)start, "%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) &&
  1400. (sscanf((char*)stop, "%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))
  1401. {
  1402. tmStart.tm_year -= 1900;
  1403. tmStart.tm_mon -= 1;
  1404. tbStart.time = mktime(&tmStart);
  1405. tbStart.millitm = 0;
  1406. tmStop.tm_year -= 1900;
  1407. tmStop.tm_mon -= 1;
  1408. tbStop.time = mktime(&tmStop);
  1409. tbStop.millitm = 0;
  1410. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1411. }
  1412. return result;
  1413. }
  1414. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1415. {
  1416. FILE *fp;
  1417. char profileFileName[128];
  1418. char *line = NULL;
  1419. size_t len = 0;
  1420. time_t CurrentTime;
  1421. struct tm *tmComposite;
  1422. struct StructChargingProfile maxProfile;
  1423. uint8_t limitMax=0;
  1424. int compositePeriodIdx = 0;
  1425. CurrentTime = time(NULL);
  1426. tmComposite=localtime(&CurrentTime);
  1427. 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);
  1428. if(isUnitA)
  1429. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1430. else
  1431. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1432. compositeProfile->ChargingSchedule.Duration = durationReq;
  1433. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1434. {
  1435. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1436. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1437. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1438. }
  1439. compositeProfile->ChargingProfileId = 0;
  1440. compositeProfile->StackLevel = 99 ;
  1441. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1442. maxProfile.ChargingProfileId = -1;
  1443. maxProfile.ChargingSchedule.Duration = -1;
  1444. system("rm -f /tmp/*.json");
  1445. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1446. // Search max profile
  1447. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1448. if((access(profileFileName, F_OK))!=-1)
  1449. {
  1450. fp = fopen(profileFileName, "r");
  1451. while(getline(&line, &len, fp) != -1)
  1452. {
  1453. json_object *obj = NULL;
  1454. obj = json_tokener_parse(line);
  1455. if(is_error(obj))
  1456. {
  1457. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1458. }
  1459. else
  1460. {
  1461. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1462. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1463. )
  1464. {
  1465. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1466. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1467. )
  1468. {
  1469. struct tm tmFrom, tmTo;
  1470. struct timeb tbFrom, tbTo;
  1471. 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) &&
  1472. (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))
  1473. {
  1474. tmFrom.tm_year -= 1900;
  1475. tmFrom.tm_mon -= 1;
  1476. tbFrom.time = mktime(&tmFrom);
  1477. tmTo.tm_year -= 1900;
  1478. tmTo.tm_mon -= 1;
  1479. tbTo.time = mktime(&tmTo);
  1480. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1481. {
  1482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1483. {
  1484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1487. }
  1488. maxProfile.ChargingProfileId = -1;
  1489. maxProfile.StackLevel = -1;
  1490. if(maxProfile.ChargingProfileId == -1)
  1491. DEBUG_INFO("MaxProfile found.\n");
  1492. else
  1493. DEBUG_INFO("MaxProfile updated.\n");
  1494. // Required item
  1495. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1496. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1497. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1498. if(isUnitA)
  1499. {
  1500. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1501. 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++)
  1502. {
  1503. 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"));
  1504. 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?
  1505. 3:
  1506. 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")));
  1507. 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")));
  1508. }
  1509. }
  1510. else
  1511. {
  1512. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1513. 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++)
  1514. {
  1515. 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"));
  1516. 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?
  1517. 3:
  1518. 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")));
  1519. 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));
  1520. }
  1521. }
  1522. // Optional item
  1523. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1524. {
  1525. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1526. }
  1527. else
  1528. {
  1529. sprintf((char*)maxProfile.ValidFrom, " ");
  1530. }
  1531. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1532. {
  1533. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1534. }
  1535. else
  1536. {
  1537. sprintf((char*)maxProfile.ValidTo, " ");
  1538. }
  1539. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1540. {
  1541. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1542. }
  1543. else
  1544. {
  1545. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1546. }
  1547. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1548. {
  1549. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1550. }
  1551. else
  1552. {
  1553. maxProfile.TransactionId = -1;
  1554. }
  1555. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1556. {
  1557. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1558. }
  1559. else
  1560. {
  1561. maxProfile.ChargingSchedule.Duration = 86400;
  1562. }
  1563. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1564. {
  1565. 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")));
  1566. }
  1567. else
  1568. {
  1569. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1570. }
  1571. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1572. {
  1573. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1574. }
  1575. else
  1576. {
  1577. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1578. }
  1579. }
  1580. }
  1581. }
  1582. else
  1583. {
  1584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1585. {
  1586. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1587. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1589. }
  1590. maxProfile.ChargingProfileId = -1;
  1591. maxProfile.StackLevel = -1;
  1592. if(maxProfile.ChargingProfileId == -1)
  1593. DEBUG_INFO("MaxProfile found.\n");
  1594. else
  1595. DEBUG_INFO("MaxProfile updated.\n");
  1596. // Required item
  1597. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1598. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1599. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1600. if(isUnitA)
  1601. {
  1602. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1603. 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++)
  1604. {
  1605. 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"));
  1606. 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?
  1607. 3:
  1608. 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")));
  1609. 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")));
  1610. }
  1611. }
  1612. else
  1613. {
  1614. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1615. 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++)
  1616. {
  1617. 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"));
  1618. 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?
  1619. 3:
  1620. 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")));
  1621. 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));
  1622. }
  1623. }
  1624. // Optional item
  1625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1626. {
  1627. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1628. }
  1629. else
  1630. {
  1631. sprintf((char*)maxProfile.ValidFrom, " ");
  1632. }
  1633. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1634. {
  1635. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1636. }
  1637. else
  1638. {
  1639. sprintf((char*)maxProfile.ValidTo, " ");
  1640. }
  1641. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1642. {
  1643. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1644. }
  1645. else
  1646. {
  1647. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1648. }
  1649. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1650. {
  1651. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1652. }
  1653. else
  1654. {
  1655. maxProfile.TransactionId = -1;
  1656. }
  1657. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1658. {
  1659. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1660. }
  1661. else
  1662. {
  1663. maxProfile.ChargingSchedule.Duration = 86400;
  1664. }
  1665. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1666. {
  1667. 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")));
  1668. }
  1669. else
  1670. {
  1671. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1672. }
  1673. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1674. {
  1675. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1676. }
  1677. else
  1678. {
  1679. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1680. }
  1681. }
  1682. }
  1683. }
  1684. json_object_put(obj);
  1685. }
  1686. fclose(fp);
  1687. /*
  1688. if(maxProfile.ChargingProfileId !=-1)
  1689. {
  1690. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1691. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1692. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1693. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1694. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1695. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1696. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1697. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1698. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1699. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1700. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1704. {
  1705. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1706. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1707. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1708. }
  1709. }
  1710. }
  1711. else
  1712. DEBUG_INFO("MaxProfile not found.\n");
  1713. DEBUG_INFO("------------------------------------\n");*/
  1714. }
  1715. if(maxProfile.ChargingProfileId != -1)
  1716. {
  1717. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1718. {
  1719. if(maxProfile.ChargingSchedule.Duration != -1)
  1720. {
  1721. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1722. 0:
  1723. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1724. }
  1725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1726. {
  1727. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1728. {
  1729. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1730. 0:
  1731. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1732. if(idxPeriod > 0)
  1733. {
  1734. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1735. {
  1736. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1737. }
  1738. }
  1739. }
  1740. }
  1741. }
  1742. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1743. {
  1744. if(maxProfile.ChargingSchedule.Duration != -1)
  1745. {
  1746. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1747. }
  1748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1749. {
  1750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1751. {
  1752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1753. if(idxPeriod > 0)
  1754. {
  1755. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1756. {
  1757. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. else
  1764. {
  1765. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1766. {
  1767. if(maxProfile.ChargingSchedule.Duration != -1)
  1768. {
  1769. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1770. 0:
  1771. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1772. }
  1773. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1774. {
  1775. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1776. {
  1777. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1778. 0:
  1779. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1780. if(idxPeriod > 0)
  1781. {
  1782. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1783. {
  1784. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. else
  1791. {
  1792. if(maxProfile.ChargingSchedule.Duration != -1)
  1793. {
  1794. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1795. 0:
  1796. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1797. }
  1798. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1799. {
  1800. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1801. {
  1802. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1803. 0:
  1804. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1805. if(idxPeriod > 0)
  1806. {
  1807. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1808. {
  1809. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. /*
  1817. DEBUG_INFO("MaxProfile after align.\n");
  1818. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1819. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1820. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1821. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1822. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1823. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1824. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1825. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1826. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1827. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1828. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1830. {
  1831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1832. {
  1833. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1834. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1835. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1836. }
  1837. }
  1838. DEBUG_INFO("------------------------------------\n");*/
  1839. }
  1840. // Find each profile period quantity
  1841. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1842. {
  1843. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1844. limitMax = idx+1;
  1845. }
  1846. if(maxProfile.ChargingProfileId != -1)
  1847. {
  1848. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1849. {
  1850. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1851. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1852. (maxProfile.ChargingSchedule.Duration > 0))
  1853. {
  1854. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1855. {
  1856. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1857. compositePeriodIdx++;
  1858. }
  1859. else
  1860. {
  1861. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1862. }
  1863. }
  1864. }
  1865. }
  1866. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1867. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1868. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1869. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1871. {
  1872. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1873. {
  1874. compositeProfile->ChargingProfileId = 1;
  1875. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1876. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1877. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1878. }
  1879. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1880. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1881. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1882. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1883. }
  1884. if(line)
  1885. free(line);
  1886. }
  1887. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1888. {
  1889. FILE *fp;
  1890. char profileFileName[128];
  1891. char *line = NULL;
  1892. size_t len = 0;
  1893. time_t CurrentTime;
  1894. struct tm *tmComposite;
  1895. struct StructChargingProfile maxProfile;
  1896. struct StructChargingProfile defaultTxProfile;
  1897. struct StructChargingProfile txProfile;
  1898. struct StructChargingSchedulePeriod tmpPeriod;
  1899. uint8_t limitMax=0;
  1900. uint8_t limitDef=0;
  1901. uint8_t limitTx=0;
  1902. int compositePeriodIdx = 0;
  1903. CurrentTime = time(NULL);
  1904. tmComposite=localtime(&CurrentTime);
  1905. 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);
  1906. if(isUnitA)
  1907. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1908. else
  1909. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1910. compositeProfile->ChargingSchedule.Duration = durationReq;
  1911. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1912. {
  1913. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1914. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1915. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1916. }
  1917. compositeProfile->ChargingProfileId = 0;
  1918. compositeProfile->StackLevel = 99 ;
  1919. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1920. maxProfile.ChargingProfileId = -1;
  1921. defaultTxProfile.ChargingProfileId = -1;
  1922. txProfile.ChargingProfileId = -1;
  1923. maxProfile.ChargingSchedule.Duration = -1;
  1924. defaultTxProfile.ChargingSchedule.Duration = -1;
  1925. txProfile.ChargingSchedule.Duration = -1;
  1926. system("rm -f /tmp/*.json");
  1927. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1928. /*
  1929. * Search valid charging profile
  1930. */
  1931. //DEBUG_INFO("====================================\n");
  1932. // Search tx profile
  1933. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1934. if((access(profileFileName, F_OK))!=-1)
  1935. {
  1936. fp = fopen(profileFileName, "r");
  1937. while(getline(&line, &len, fp) != -1)
  1938. {
  1939. json_object *obj = NULL;
  1940. obj = json_tokener_parse(line);
  1941. if(is_error(obj))
  1942. {
  1943. DEBUG_ERROR("Parse txProfile from file error.\n");
  1944. }
  1945. else
  1946. {
  1947. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1948. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1949. )
  1950. {
  1951. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1952. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1953. )
  1954. {
  1955. struct tm tmFrom, tmTo;
  1956. struct timeb tbFrom, tbTo;
  1957. 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) &&
  1958. (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))
  1959. {
  1960. tmFrom.tm_year -= 1900;
  1961. tmFrom.tm_mon -= 1;
  1962. tbFrom.time = mktime(&tmFrom);
  1963. tmTo.tm_year -= 1900;
  1964. tmTo.tm_mon -= 1;
  1965. tbTo.time = mktime(&tmTo);
  1966. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1967. {
  1968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1969. {
  1970. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1971. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1972. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1973. }
  1974. txProfile.ChargingProfileId = -1;
  1975. txProfile.StackLevel = -1;
  1976. if(txProfile.ChargingProfileId == -1)
  1977. DEBUG_INFO("TxProfile found.\n");
  1978. else
  1979. DEBUG_INFO("TxProfile updated.\n");
  1980. // Required item
  1981. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1982. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1983. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1984. if(isUnitA)
  1985. {
  1986. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1987. 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++)
  1988. {
  1989. 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"));
  1990. 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?
  1991. 3:
  1992. 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")));
  1993. 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")));
  1994. }
  1995. }
  1996. else
  1997. {
  1998. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1999. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2000. {
  2001. 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"));
  2002. 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?
  2003. 3:
  2004. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2005. 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));
  2006. }
  2007. }
  2008. // Optional item
  2009. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2010. {
  2011. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2012. }
  2013. else
  2014. {
  2015. sprintf((char*)txProfile.ValidFrom, " ");
  2016. }
  2017. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2018. {
  2019. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2020. }
  2021. else
  2022. {
  2023. sprintf((char*)txProfile.ValidTo, " ");
  2024. }
  2025. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2026. {
  2027. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2028. }
  2029. else
  2030. {
  2031. sprintf((char*)txProfile.RecurrencyKind, " ");
  2032. }
  2033. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2034. {
  2035. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2036. }
  2037. else
  2038. {
  2039. txProfile.TransactionId = -1;
  2040. }
  2041. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2042. {
  2043. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2044. }
  2045. else
  2046. {
  2047. txProfile.ChargingSchedule.Duration = 86400;
  2048. }
  2049. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2050. {
  2051. 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")));
  2052. }
  2053. else
  2054. {
  2055. 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));
  2056. }
  2057. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2058. {
  2059. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2060. }
  2061. else
  2062. {
  2063. txProfile.ChargingSchedule.MinChargingRate = -1;
  2064. }
  2065. }
  2066. }
  2067. }
  2068. else
  2069. {
  2070. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2071. {
  2072. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2073. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2074. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2075. }
  2076. txProfile.ChargingProfileId = -1;
  2077. txProfile.StackLevel = -1;
  2078. if(txProfile.ChargingProfileId == -1)
  2079. DEBUG_INFO("TxProfile found.\n");
  2080. else
  2081. DEBUG_INFO("TxProfile updated.\n");
  2082. // Required item
  2083. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2084. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2085. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2086. if(isUnitA)
  2087. {
  2088. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2089. 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++)
  2090. {
  2091. 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"));
  2092. 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?
  2093. 3:
  2094. 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")));
  2095. 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")));
  2096. }
  2097. }
  2098. else
  2099. {
  2100. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2101. 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++)
  2102. {
  2103. 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"));
  2104. 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?
  2105. 3:
  2106. 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")));
  2107. 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));
  2108. }
  2109. }
  2110. // Optional item
  2111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2112. {
  2113. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2114. }
  2115. else
  2116. {
  2117. sprintf((char*)txProfile.ValidFrom, " ");
  2118. }
  2119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2120. {
  2121. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2122. }
  2123. else
  2124. {
  2125. sprintf((char*)txProfile.ValidTo, " ");
  2126. }
  2127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2128. {
  2129. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2130. }
  2131. else
  2132. {
  2133. sprintf((char*)txProfile.RecurrencyKind, " ");
  2134. }
  2135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2136. {
  2137. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2138. }
  2139. else
  2140. {
  2141. txProfile.TransactionId = -1;
  2142. }
  2143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2144. {
  2145. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2146. }
  2147. else
  2148. {
  2149. txProfile.ChargingSchedule.Duration = 86400;
  2150. }
  2151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2152. {
  2153. 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")));
  2154. }
  2155. else
  2156. {
  2157. 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));
  2158. }
  2159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2160. {
  2161. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2162. }
  2163. else
  2164. {
  2165. txProfile.ChargingSchedule.MinChargingRate = -1;
  2166. }
  2167. }
  2168. }
  2169. }
  2170. json_object_put(obj);
  2171. }
  2172. fclose(fp);
  2173. /*
  2174. if(txProfile.ChargingProfileId != -1)
  2175. {
  2176. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2177. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2178. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2179. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2180. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2181. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2182. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2183. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2184. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2185. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2186. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2188. {
  2189. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2190. {
  2191. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2192. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2193. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2194. }
  2195. }
  2196. }
  2197. else
  2198. DEBUG_INFO("TxProfile not found.\n");*/
  2199. }
  2200. // Search default tx profile
  2201. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2202. if((access(profileFileName, F_OK))==-1)
  2203. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2204. if((access(profileFileName, F_OK))!=-1)
  2205. {
  2206. fp = fopen(profileFileName, "r");
  2207. while(getline(&line, &len, fp) != -1)
  2208. {
  2209. json_object *obj = NULL;
  2210. obj = json_tokener_parse(line);
  2211. if(is_error(obj))
  2212. {
  2213. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2214. }
  2215. else
  2216. {
  2217. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2218. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2219. )
  2220. {
  2221. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2222. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2223. )
  2224. {
  2225. struct tm tmFrom, tmTo;
  2226. struct timeb tbFrom, tbTo;
  2227. 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) &&
  2228. (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))
  2229. {
  2230. tmFrom.tm_year -= 1900;
  2231. tmFrom.tm_mon -= 1;
  2232. tbFrom.time = mktime(&tmFrom);
  2233. tmTo.tm_year -= 1900;
  2234. tmTo.tm_mon -= 1;
  2235. tbTo.time = mktime(&tmTo);
  2236. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2237. {
  2238. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2239. {
  2240. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2241. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2242. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2243. }
  2244. defaultTxProfile.ChargingProfileId = -1;
  2245. defaultTxProfile.StackLevel = -1;
  2246. if(defaultTxProfile.ChargingProfileId == -1)
  2247. DEBUG_INFO("TxDefaultProfile found.\n");
  2248. else
  2249. DEBUG_INFO("TxDefaultProfile updated.\n");
  2250. // Required item
  2251. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2252. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2253. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2254. if(isUnitA)
  2255. {
  2256. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2257. 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++)
  2258. {
  2259. 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"));
  2260. 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?
  2261. 3:
  2262. 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")));
  2263. 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")));
  2264. }
  2265. }
  2266. else
  2267. {
  2268. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2269. 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++)
  2270. {
  2271. 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"));
  2272. 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?
  2273. 3:
  2274. 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")));
  2275. 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));
  2276. }
  2277. }
  2278. // Optional item
  2279. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2280. {
  2281. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2282. }
  2283. else
  2284. {
  2285. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2286. }
  2287. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2288. {
  2289. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2290. }
  2291. else
  2292. {
  2293. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2294. }
  2295. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2296. {
  2297. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2298. }
  2299. else
  2300. {
  2301. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2302. }
  2303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2304. {
  2305. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2306. }
  2307. else
  2308. {
  2309. defaultTxProfile.TransactionId = -1;
  2310. }
  2311. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2312. {
  2313. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2314. }
  2315. else
  2316. {
  2317. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2318. }
  2319. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2320. {
  2321. 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")));
  2322. }
  2323. else
  2324. {
  2325. 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));
  2326. }
  2327. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2328. {
  2329. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2330. }
  2331. else
  2332. {
  2333. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2334. }
  2335. }
  2336. }
  2337. }
  2338. else
  2339. {
  2340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2341. {
  2342. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2343. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2344. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2345. }
  2346. defaultTxProfile.ChargingProfileId = -1;
  2347. defaultTxProfile.StackLevel = -1;
  2348. if(defaultTxProfile.ChargingProfileId == -1)
  2349. DEBUG_INFO("TxDefaultProfile found.\n");
  2350. else
  2351. DEBUG_INFO("TxDefaultProfile updated.\n");
  2352. // Required item
  2353. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2354. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2355. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2356. if(isUnitA)
  2357. {
  2358. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2359. 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++)
  2360. {
  2361. 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"));
  2362. 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?
  2363. 3:
  2364. 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")));
  2365. 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")));
  2366. }
  2367. }
  2368. else
  2369. {
  2370. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2371. 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++)
  2372. {
  2373. 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"));
  2374. 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?
  2375. 3:
  2376. 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")));
  2377. 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));
  2378. }
  2379. }
  2380. // Optional item
  2381. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2382. {
  2383. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2384. }
  2385. else
  2386. {
  2387. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2388. }
  2389. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2390. {
  2391. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2392. }
  2393. else
  2394. {
  2395. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2396. }
  2397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2398. {
  2399. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2400. }
  2401. else
  2402. {
  2403. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2404. }
  2405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2406. {
  2407. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2408. }
  2409. else
  2410. {
  2411. defaultTxProfile.TransactionId = -1;
  2412. }
  2413. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2414. {
  2415. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2416. }
  2417. else
  2418. {
  2419. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2420. }
  2421. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2422. {
  2423. 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")));
  2424. }
  2425. else
  2426. {
  2427. 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));
  2428. }
  2429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2430. {
  2431. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2432. }
  2433. else
  2434. {
  2435. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2436. }
  2437. }
  2438. }
  2439. }
  2440. json_object_put(obj);
  2441. }
  2442. fclose(fp);
  2443. /*
  2444. if(defaultTxProfile.ChargingProfileId != -1)
  2445. {
  2446. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2447. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2448. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2449. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2450. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2451. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2452. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2453. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2454. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2455. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2456. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2457. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2458. {
  2459. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2460. {
  2461. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2462. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2463. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2464. }
  2465. }
  2466. }
  2467. else
  2468. DEBUG_INFO("TxDefaultProfile not found.\n");
  2469. DEBUG_INFO("------------------------------------\n");*/
  2470. }
  2471. // Search max profile
  2472. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2473. if((access(profileFileName, F_OK))!=-1)
  2474. {
  2475. fp = fopen(profileFileName, "r");
  2476. while(getline(&line, &len, fp) != -1)
  2477. {
  2478. json_object *obj = NULL;
  2479. obj = json_tokener_parse(line);
  2480. if(is_error(obj))
  2481. {
  2482. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2483. }
  2484. else
  2485. {
  2486. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2487. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2488. )
  2489. {
  2490. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2491. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2492. )
  2493. {
  2494. struct tm tmFrom, tmTo;
  2495. struct timeb tbFrom, tbTo;
  2496. 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) &&
  2497. (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))
  2498. {
  2499. tmFrom.tm_year -= 1900;
  2500. tmFrom.tm_mon -= 1;
  2501. tbFrom.time = mktime(&tmFrom);
  2502. tmTo.tm_year -= 1900;
  2503. tmTo.tm_mon -= 1;
  2504. tbTo.time = mktime(&tmTo);
  2505. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2506. {
  2507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2508. {
  2509. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2510. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2512. }
  2513. maxProfile.ChargingProfileId = -1;
  2514. maxProfile.StackLevel = -1;
  2515. if(maxProfile.ChargingProfileId == -1)
  2516. DEBUG_INFO("MaxProfile found.\n");
  2517. else
  2518. DEBUG_INFO("MaxProfile updated.\n");
  2519. // Required item
  2520. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2521. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2522. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2523. if(isUnitA)
  2524. {
  2525. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2526. 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++)
  2527. {
  2528. 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"));
  2529. 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?
  2530. 3:
  2531. 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")));
  2532. 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")));
  2533. }
  2534. }
  2535. else
  2536. {
  2537. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2538. 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++)
  2539. {
  2540. 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"));
  2541. 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?
  2542. 3:
  2543. 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")));
  2544. 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));
  2545. }
  2546. }
  2547. // Optional item
  2548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2549. {
  2550. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2551. }
  2552. else
  2553. {
  2554. sprintf((char*)maxProfile.ValidFrom, " ");
  2555. }
  2556. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2557. {
  2558. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2559. }
  2560. else
  2561. {
  2562. sprintf((char*)maxProfile.ValidTo, " ");
  2563. }
  2564. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2565. {
  2566. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2567. }
  2568. else
  2569. {
  2570. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2571. }
  2572. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2573. {
  2574. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2575. }
  2576. else
  2577. {
  2578. maxProfile.TransactionId = -1;
  2579. }
  2580. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2581. {
  2582. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2583. }
  2584. else
  2585. {
  2586. maxProfile.ChargingSchedule.Duration = 86400;
  2587. }
  2588. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2589. {
  2590. 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")));
  2591. }
  2592. else
  2593. {
  2594. 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));
  2595. }
  2596. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2597. {
  2598. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2599. }
  2600. else
  2601. {
  2602. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2603. }
  2604. }
  2605. }
  2606. }
  2607. else
  2608. {
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2612. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2613. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2614. }
  2615. maxProfile.ChargingProfileId = -1;
  2616. maxProfile.StackLevel = -1;
  2617. if(maxProfile.ChargingProfileId == -1)
  2618. DEBUG_INFO("MaxProfile found.\n");
  2619. else
  2620. DEBUG_INFO("MaxProfile updated.\n");
  2621. // Required item
  2622. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2623. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2624. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2625. if(isUnitA)
  2626. {
  2627. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2628. 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++)
  2629. {
  2630. 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"));
  2631. 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?
  2632. 3:
  2633. 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")));
  2634. 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")));
  2635. }
  2636. }
  2637. else
  2638. {
  2639. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2640. 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++)
  2641. {
  2642. 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"));
  2643. 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?
  2644. 3:
  2645. 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")));
  2646. 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));
  2647. }
  2648. }
  2649. // Optional item
  2650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2651. {
  2652. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2653. }
  2654. else
  2655. {
  2656. sprintf((char*)maxProfile.ValidFrom, " ");
  2657. }
  2658. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2659. {
  2660. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2661. }
  2662. else
  2663. {
  2664. sprintf((char*)maxProfile.ValidTo, " ");
  2665. }
  2666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2667. {
  2668. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2669. }
  2670. else
  2671. {
  2672. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2673. }
  2674. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2675. {
  2676. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2677. }
  2678. else
  2679. {
  2680. maxProfile.TransactionId = -1;
  2681. }
  2682. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2683. {
  2684. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2685. }
  2686. else
  2687. {
  2688. maxProfile.ChargingSchedule.Duration = 86400;
  2689. }
  2690. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2691. {
  2692. 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")));
  2693. }
  2694. else
  2695. {
  2696. 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));
  2697. }
  2698. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2699. {
  2700. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2701. }
  2702. else
  2703. {
  2704. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2705. }
  2706. }
  2707. }
  2708. }
  2709. json_object_put(obj);
  2710. }
  2711. fclose(fp);
  2712. /*
  2713. if(maxProfile.ChargingProfileId !=-1)
  2714. {
  2715. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2716. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2717. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2718. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2719. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2720. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2721. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2722. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2723. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2724. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2725. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2727. {
  2728. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2729. {
  2730. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2731. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2732. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2733. }
  2734. }
  2735. }
  2736. else
  2737. DEBUG_INFO("MaxProfile not found.\n");
  2738. DEBUG_INFO("------------------------------------\n");*/
  2739. }
  2740. /*
  2741. * Align found profile start schedule & periods
  2742. */
  2743. //DEBUG_INFO("====================================\n");
  2744. /*
  2745. // For local test usage, force modify found profile start schedule info
  2746. 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);
  2747. 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);
  2748. 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);
  2749. */
  2750. if(txProfile.ChargingProfileId != -1)
  2751. {
  2752. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2753. {
  2754. if(txProfile.ChargingSchedule.Duration != -1)
  2755. {
  2756. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2757. 0:
  2758. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2759. }
  2760. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2761. {
  2762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2763. {
  2764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2765. 0:
  2766. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2767. if(idxPeriod > 0)
  2768. {
  2769. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2770. {
  2771. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2772. }
  2773. }
  2774. }
  2775. }
  2776. }
  2777. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2778. {
  2779. if(txProfile.ChargingSchedule.Duration != -1)
  2780. {
  2781. 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?
  2782. 0:
  2783. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2784. }
  2785. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2786. {
  2787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2788. {
  2789. 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?
  2790. 0:
  2791. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2792. if(idxPeriod > 0)
  2793. {
  2794. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2795. {
  2796. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2797. }
  2798. }
  2799. }
  2800. }
  2801. }
  2802. else
  2803. {
  2804. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2805. {
  2806. if(txProfile.ChargingSchedule.Duration != -1)
  2807. {
  2808. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2809. 0:
  2810. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2811. }
  2812. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2813. {
  2814. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2815. {
  2816. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2817. 0:
  2818. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2819. if(idxPeriod > 0)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2822. {
  2823. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2824. }
  2825. }
  2826. }
  2827. }
  2828. }
  2829. else
  2830. {
  2831. if(txProfile.ChargingSchedule.Duration != -1)
  2832. {
  2833. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2834. 0:
  2835. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2836. }
  2837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2838. {
  2839. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2840. {
  2841. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2842. 0:
  2843. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2844. if(idxPeriod > 0)
  2845. {
  2846. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2847. {
  2848. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. /*
  2856. DEBUG_INFO("txProfile after align.\n");
  2857. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2858. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2859. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2860. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2861. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2862. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2863. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2864. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2865. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2866. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2867. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2868. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2869. {
  2870. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2871. {
  2872. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2873. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2874. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2875. }
  2876. }*/
  2877. }
  2878. if(defaultTxProfile.ChargingProfileId != -1)
  2879. {
  2880. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2881. {
  2882. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2883. {
  2884. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2885. 0:
  2886. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2887. }
  2888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2889. {
  2890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2891. {
  2892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2893. 0:
  2894. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2896. {
  2897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2898. }
  2899. if(idxPeriod > 0)
  2900. {
  2901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2902. {
  2903. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2904. }
  2905. }
  2906. }
  2907. }
  2908. }
  2909. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2910. {
  2911. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2912. {
  2913. 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?
  2914. 0:
  2915. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2916. }
  2917. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2918. {
  2919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2920. {
  2921. 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?
  2922. 0:
  2923. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2924. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2925. {
  2926. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2927. }
  2928. if(idxPeriod > 0)
  2929. {
  2930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2931. {
  2932. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2933. }
  2934. }
  2935. }
  2936. }
  2937. }
  2938. else
  2939. {
  2940. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2941. {
  2942. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2943. {
  2944. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2945. 0:
  2946. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2947. }
  2948. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2949. {
  2950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2951. {
  2952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2953. 0:
  2954. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2955. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2956. {
  2957. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2958. }
  2959. if(idxPeriod > 0)
  2960. {
  2961. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2962. {
  2963. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2964. }
  2965. }
  2966. }
  2967. }
  2968. }
  2969. else
  2970. {
  2971. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2972. {
  2973. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2974. 0:
  2975. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2976. }
  2977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2978. {
  2979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2980. {
  2981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2982. 0:
  2983. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2984. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2985. {
  2986. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2987. }
  2988. if(idxPeriod > 0)
  2989. {
  2990. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2991. {
  2992. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }
  2998. }
  2999. /*
  3000. DEBUG_INFO("defaultTxProfile after align.\n");
  3001. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3002. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3003. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3004. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3005. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3006. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3007. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3008. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3009. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3010. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3011. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3013. {
  3014. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3015. {
  3016. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3017. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3018. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3019. }
  3020. }
  3021. DEBUG_INFO("------------------------------------\n");*/
  3022. }
  3023. if(maxProfile.ChargingProfileId != -1)
  3024. {
  3025. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3026. {
  3027. if(maxProfile.ChargingSchedule.Duration != -1)
  3028. {
  3029. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3030. 0:
  3031. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3032. }
  3033. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3034. {
  3035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3036. {
  3037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3038. 0:
  3039. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3040. if(idxPeriod > 0)
  3041. {
  3042. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3043. {
  3044. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3045. }
  3046. }
  3047. }
  3048. }
  3049. }
  3050. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3051. {
  3052. if(maxProfile.ChargingSchedule.Duration != -1)
  3053. {
  3054. 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?
  3055. 0:
  3056. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3057. }
  3058. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3059. {
  3060. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3061. {
  3062. 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?
  3063. 0:
  3064. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3065. if(idxPeriod > 0)
  3066. {
  3067. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3068. {
  3069. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. }
  3075. else
  3076. {
  3077. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3078. {
  3079. if(maxProfile.ChargingSchedule.Duration != -1)
  3080. {
  3081. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3082. 0:
  3083. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3084. }
  3085. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3086. {
  3087. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3088. {
  3089. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3090. 0:
  3091. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3092. if(idxPeriod > 0)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3095. {
  3096. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. else
  3103. {
  3104. if(maxProfile.ChargingSchedule.Duration != -1)
  3105. {
  3106. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3107. 0:
  3108. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3109. }
  3110. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3111. {
  3112. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3113. {
  3114. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3115. 0:
  3116. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3117. if(idxPeriod > 0)
  3118. {
  3119. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3120. {
  3121. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3122. }
  3123. }
  3124. }
  3125. }
  3126. }
  3127. }
  3128. /*
  3129. DEBUG_INFO("MaxProfile after align.\n");
  3130. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3131. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3132. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3133. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3134. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3135. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3136. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3137. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3138. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3139. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3140. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3141. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3142. {
  3143. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3144. {
  3145. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3146. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3147. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3148. }
  3149. }
  3150. DEBUG_INFO("------------------------------------\n");*/
  3151. }
  3152. /*
  3153. * Merge to conposite schedule
  3154. */
  3155. //DEBUG_INFO("====================================\n");
  3156. // Find each profile period quantity
  3157. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3158. {
  3159. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3160. limitMax = idx+1;
  3161. }
  3162. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3163. {
  3164. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3165. limitDef = idx+1;
  3166. }
  3167. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3168. {
  3169. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3170. limitTx = idx+1;
  3171. }
  3172. // TxProfile found, composite schedule based on it
  3173. if(txProfile.ChargingProfileId != -1)
  3174. {
  3175. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3176. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3177. {
  3178. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3179. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3180. (txProfile.ChargingSchedule.Duration > 0))
  3181. {
  3182. if(maxProfile.ChargingProfileId != -1)
  3183. {
  3184. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3185. {
  3186. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3187. {
  3188. if((maxProfile.ChargingSchedule.Duration > 0))
  3189. {
  3190. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3191. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3192. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3193. }
  3194. else
  3195. {
  3196. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3197. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3198. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3199. }
  3200. }
  3201. if(idxMaxPeriod == (limitMax-1))
  3202. {
  3203. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3204. {
  3205. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3206. {
  3207. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3208. compositePeriodIdx++;
  3209. }
  3210. else
  3211. {
  3212. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3213. }
  3214. }
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. }
  3230. }
  3231. if(idxTxPeriod == (limitTx-1))
  3232. {
  3233. if(defaultTxProfile.ChargingProfileId != -1)
  3234. {
  3235. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3236. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3237. {
  3238. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3239. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3240. (defaultTxProfile.ChargingSchedule.Duration>0))
  3241. {
  3242. if(maxProfile.ChargingProfileId != -1)
  3243. {
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3247. {
  3248. if((maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3251. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3252. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3253. }
  3254. else
  3255. {
  3256. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3257. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3258. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3259. }
  3260. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3261. {
  3262. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3263. {
  3264. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3265. compositePeriodIdx++;
  3266. }
  3267. else
  3268. {
  3269. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3270. }
  3271. }
  3272. // Delete duplicate period
  3273. if(compositePeriodIdx > 1)
  3274. {
  3275. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3276. {
  3277. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3278. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3279. compositePeriodIdx -= 1;
  3280. }
  3281. }
  3282. }
  3283. else
  3284. {
  3285. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3286. {
  3287. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3288. compositePeriodIdx++;
  3289. }
  3290. else
  3291. {
  3292. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3293. }
  3294. break;
  3295. }
  3296. }
  3297. }
  3298. else
  3299. {
  3300. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3301. {
  3302. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3303. compositePeriodIdx++;
  3304. }
  3305. else
  3306. {
  3307. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3308. }
  3309. }
  3310. }
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3317. else if(defaultTxProfile.ChargingProfileId != -1)
  3318. {
  3319. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3320. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3321. {
  3322. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3323. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3324. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3325. {
  3326. if(maxProfile.ChargingProfileId != -1)
  3327. {
  3328. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3329. {
  3330. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3331. {
  3332. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3333. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3334. if((maxProfile.ChargingSchedule.Duration > 0))
  3335. {
  3336. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3337. }
  3338. else
  3339. {
  3340. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3341. }
  3342. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3343. {
  3344. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3345. {
  3346. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3347. compositePeriodIdx++;
  3348. }
  3349. else
  3350. {
  3351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3352. }
  3353. }
  3354. // Delete duplicate period
  3355. if(compositePeriodIdx > 1)
  3356. {
  3357. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3358. {
  3359. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3360. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3361. compositePeriodIdx -= 1;
  3362. }
  3363. }
  3364. }
  3365. else
  3366. {
  3367. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3368. {
  3369. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3370. compositePeriodIdx++;
  3371. }
  3372. else
  3373. {
  3374. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3375. }
  3376. break;
  3377. }
  3378. }
  3379. }
  3380. else
  3381. {
  3382. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. // Fill other period by MaxProfile
  3396. if(maxProfile.ChargingProfileId != -1)
  3397. {
  3398. if(compositePeriodIdx==0)
  3399. {
  3400. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3401. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3402. {
  3403. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3404. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3405. (maxProfile.ChargingSchedule.Duration > 0))
  3406. {
  3407. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3408. {
  3409. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3410. compositePeriodIdx++;
  3411. }
  3412. else
  3413. {
  3414. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3415. }
  3416. }
  3417. }
  3418. }
  3419. else
  3420. {
  3421. int lastCompositePeriodIdx = compositePeriodIdx;
  3422. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3423. {
  3424. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3425. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3426. (maxProfile.ChargingSchedule.Duration > 0))
  3427. {
  3428. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3431. {
  3432. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3433. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3434. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3435. }
  3436. else
  3437. {
  3438. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3439. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3440. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3441. }
  3442. }
  3443. if(tmpPeriod.Limit != -1)
  3444. {
  3445. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3446. {
  3447. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3448. {
  3449. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3450. compositePeriodIdx++;
  3451. }
  3452. else
  3453. {
  3454. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3455. }
  3456. }
  3457. // Delete duplicate period
  3458. if(compositePeriodIdx > 1)
  3459. {
  3460. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3461. {
  3462. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3463. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3464. compositePeriodIdx -= 1;
  3465. }
  3466. }
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. compositeProfile->ChargingSchedule.Duration = durationReq;
  3473. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3474. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3475. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3476. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3478. {
  3479. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3480. {
  3481. compositeProfile->ChargingProfileId = 1;
  3482. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3483. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3484. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3485. }
  3486. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3487. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3488. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3489. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3490. }
  3491. if(line)
  3492. free(line);
  3493. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3494. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3495. }
  3496. //==========================================
  3497. // Init all share memory
  3498. //==========================================
  3499. int InitShareMemory()
  3500. {
  3501. int result = PASS;
  3502. int MeterSMId;
  3503. //creat ShmSysConfigAndInfo
  3504. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3505. {
  3506. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3507. result = FAIL;
  3508. }
  3509. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3510. {
  3511. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3512. result = FAIL;
  3513. }
  3514. else
  3515. {}
  3516. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3517. {
  3518. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3519. result = FAIL;
  3520. }
  3521. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3522. {
  3523. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3524. result = FAIL;
  3525. }
  3526. else
  3527. {}
  3528. //creat ShmPsuData
  3529. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3530. {
  3531. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3532. result = FAIL;
  3533. }
  3534. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3535. {
  3536. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3537. result = FAIL;
  3538. }
  3539. else
  3540. {}
  3541. //creat ShmOCPP16Data
  3542. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3543. {
  3544. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3545. result = FAIL;
  3546. }
  3547. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3548. {
  3549. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3550. result = FAIL;
  3551. }
  3552. else
  3553. {}
  3554. /****************************** For Initial Settings************************************************/
  3555. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3556. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3557. // allocate Configuration memory address
  3558. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3559. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3560. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3561. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3562. //offline MeterValue Interval
  3563. TempMeterValueInterval = 0;
  3564. return result;
  3565. }
  3566. int ProcessShareMemory()
  3567. {
  3568. int result = PASS;
  3569. if(InitShareMemory() == FAIL)
  3570. {
  3571. DEBUG_ERROR("InitShareMemory NG\n");
  3572. if(ShmStatusCodeData!=NULL)
  3573. {
  3574. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3575. }
  3576. result = FAIL;
  3577. }
  3578. // Model name parsing
  3579. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3580. {
  3581. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3582. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3583. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3584. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3585. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3586. ) // 'D' means DC
  3587. {
  3588. // DO series
  3589. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3590. {
  3591. SystemInitial += 1;
  3592. gunTotalNumber += 1;
  3593. gunType[gun_index] = GUN_TYPE_DO;
  3594. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3595. {
  3596. case Gun_Type_Chademo:
  3597. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3598. break;
  3599. case Gun_Type_CCS_2:
  3600. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3601. break;
  3602. case Gun_Type_GB:
  3603. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3604. break;
  3605. case Gun_Type_AC:
  3606. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3607. break;
  3608. default:
  3609. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3610. break;
  3611. }
  3612. }
  3613. }
  3614. else
  3615. {
  3616. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3617. {
  3618. SystemInitial += 1;
  3619. gunTotalNumber += 1;
  3620. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3621. {
  3622. case Gun_Type_Chademo:
  3623. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3624. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3625. break;
  3626. case Gun_Type_CCS_2:
  3627. gunType[gun_index] = GUN_TYPE_CCS;
  3628. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3629. break;
  3630. case Gun_Type_GB:
  3631. gunType[gun_index] = GUN_TYPE_GBT;
  3632. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3633. break;
  3634. case Gun_Type_AC:
  3635. gunType[gun_index] = GUN_TYPE_AC;
  3636. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3637. break;
  3638. default:
  3639. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3640. break;
  3641. }
  3642. }
  3643. }
  3644. }
  3645. else
  3646. {
  3647. DEBUG_ERROR("Model name parsing fail.\n");
  3648. result = FAIL;
  3649. }
  3650. if(result != PASS)sleep(5);
  3651. return result;
  3652. }
  3653. void checkRemoteStart(uint8_t connectorIdInt)
  3654. {
  3655. uint8_t tempIndex;
  3656. int result = PASS;
  3657. char cmdBuf[512];
  3658. //check Transaction active
  3659. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3662. {
  3663. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3664. }
  3665. else
  3666. {
  3667. tempIndex = connectorIdInt -1;
  3668. }
  3669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3672. {
  3673. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3675. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3676. {
  3677. //Reserved
  3678. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3679. }
  3680. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3682. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3683. {
  3684. //Reserved
  3685. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3686. result = FAIL;
  3687. goto end;
  3688. }
  3689. else
  3690. {
  3691. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3692. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3695. {
  3696. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3697. result = FAIL;
  3698. goto end;
  3699. }
  3700. }//END FOR ELSE
  3701. }
  3702. }// END FOR CHAdeMO_QUANTITY
  3703. }
  3704. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3709. }
  3710. else
  3711. {
  3712. tempIndex = connectorIdInt -1;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3720. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3721. {
  3722. //Reserved
  3723. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3724. }
  3725. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3726. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3727. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3728. {
  3729. //Reserved
  3730. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3731. result = FAIL;
  3732. goto end;
  3733. }
  3734. else
  3735. {
  3736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3740. {
  3741. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3742. result = FAIL;
  3743. goto end;
  3744. }
  3745. }// END FOR ELSE
  3746. }
  3747. }// END FOR CCS_QUANTITY
  3748. }
  3749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3750. {
  3751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3752. {
  3753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3754. }
  3755. else
  3756. {
  3757. tempIndex = connectorIdInt -1;
  3758. }
  3759. for (int index = 0; index < GB_QUANTITY; index++)
  3760. {
  3761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3762. {
  3763. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3765. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3766. {
  3767. //Reserved
  3768. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3769. }
  3770. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3771. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3772. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3773. {
  3774. //Reserved
  3775. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3776. result = FAIL;
  3777. goto end;
  3778. }
  3779. else
  3780. {
  3781. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3782. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3785. {
  3786. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3787. result = FAIL;
  3788. goto end;
  3789. }
  3790. }// END FOR ELSE
  3791. }
  3792. } // END FOR GB_QUANTITY
  3793. }
  3794. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3795. {
  3796. tempIndex = connectorIdInt -1;
  3797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3798. {
  3799. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3800. {
  3801. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3802. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3803. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3804. {
  3805. //Reserved
  3806. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3807. }
  3808. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3809. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3810. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3811. {
  3812. //Reserved
  3813. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3814. result = FAIL;
  3815. goto end;
  3816. }
  3817. else
  3818. {
  3819. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3820. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3823. {
  3824. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3825. result = FAIL;
  3826. goto end;
  3827. }
  3828. }// END FOR ELSE
  3829. }
  3830. } // END FOR GB_QUANTITY
  3831. }
  3832. else
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3835. {
  3836. tempIndex = 2;
  3837. }
  3838. else
  3839. {
  3840. tempIndex = connectorIdInt -1;
  3841. }
  3842. for (int index = 0; index < AC_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3845. {
  3846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3847. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3848. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3849. {
  3850. //Reserved
  3851. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3852. }
  3853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3855. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3856. {
  3857. //Reserved
  3858. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3859. result = FAIL;
  3860. goto end;
  3861. }
  3862. else
  3863. {
  3864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3865. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3868. {
  3869. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3870. result = FAIL;
  3871. goto end;
  3872. }
  3873. }//END FOR ELSE
  3874. }
  3875. }// END FOR AC_QUANTITY
  3876. }
  3877. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3878. {
  3879. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3880. {
  3881. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3882. {
  3883. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3884. system(cmdBuf);
  3885. }
  3886. }
  3887. else
  3888. {
  3889. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3890. result = FAIL;
  3891. }
  3892. }
  3893. end:
  3894. if(result == PASS)
  3895. {
  3896. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3897. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3898. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3899. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3900. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3901. }
  3902. }
  3903. void CheckSystemValue(void)
  3904. {
  3905. char filenmae[100]={0};
  3906. char str[100]={0};
  3907. int tempIndex = 0;
  3908. //===============================
  3909. // send Heartbeat
  3910. //===============================
  3911. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3912. {
  3913. //parameter for test
  3914. sendHeartbeatRequest(0);
  3915. //==============================================
  3916. // Reset Waiting Time
  3917. //==============================================
  3918. HeartBeatWithNOResponse += 1;
  3919. }
  3920. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3921. {
  3922. // ClockAlign MeterValue
  3923. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3924. {
  3925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3926. {
  3927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3928. {
  3929. tempIndex = ((gun_index==2) ? 1: 0);
  3930. }
  3931. else
  3932. {
  3933. tempIndex = gun_index;
  3934. }
  3935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3936. {
  3937. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3938. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3939. {
  3940. reqClockAlignMeter[gun_index] = 1;
  3941. }
  3942. }// End for CHAdeMO
  3943. }
  3944. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3945. {
  3946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3947. {
  3948. tempIndex = ((gun_index==2) ? 1: 0);
  3949. }
  3950. else
  3951. {
  3952. tempIndex = gun_index;
  3953. }
  3954. for (int index = 0; index < CCS_QUANTITY; index++)
  3955. {
  3956. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3957. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3958. {
  3959. reqClockAlignMeter[gun_index] = 1;
  3960. }
  3961. } // End for CCS
  3962. }
  3963. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3964. {
  3965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3966. {
  3967. tempIndex = ((gun_index==2) ? 1: 0);
  3968. }
  3969. else
  3970. {
  3971. tempIndex = gun_index;
  3972. }
  3973. for (int index = 0; index < GB_QUANTITY; index++)
  3974. {
  3975. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3976. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3977. {
  3978. reqClockAlignMeter[gun_index] = 1;
  3979. }
  3980. }// End for GB
  3981. }
  3982. else if(gunType[gun_index] == GUN_TYPE_DO)
  3983. {
  3984. tempIndex = gun_index;
  3985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3986. {
  3987. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3988. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3989. {
  3990. reqClockAlignMeter[gun_index] = 1;
  3991. }
  3992. }
  3993. }
  3994. else
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3997. {
  3998. tempIndex = 2;
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < AC_QUANTITY; index++)
  4005. {
  4006. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4007. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4008. {
  4009. reqClockAlignMeter[gun_index] = 1;
  4010. }
  4011. }//End for AC
  4012. }
  4013. }
  4014. }
  4015. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4016. {
  4017. //==========================================
  4018. // Check remote start without connector id
  4019. //==========================================
  4020. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4021. {
  4022. int connectorIdInt = -1;
  4023. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4024. {
  4025. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4026. {
  4027. connectorIdInt = (gun_index+1);
  4028. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4029. checkRemoteStart(connectorIdInt);
  4030. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4031. break;
  4032. }
  4033. }
  4034. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4035. {
  4036. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4037. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4038. }
  4039. }
  4040. //==========================================
  4041. // csu trigger DataTransferReq
  4042. //==========================================
  4043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4044. {
  4045. sendDataTransferRequest(gun_index);
  4046. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4047. }
  4048. //==========================================
  4049. // CSU Trigger Authorize Request
  4050. //==========================================
  4051. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4052. {
  4053. sendAuthorizeRequest(0);
  4054. authorizeRetryTimes = authorizeRetryTimes + 1;
  4055. if(authorizeRetryTimes < 3)
  4056. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4057. }
  4058. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4059. {
  4060. authorizeRetryTimes = 0;
  4061. SetOcppConnStatus(FALSE);
  4062. server_sign = FALSE;
  4063. }
  4064. 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))
  4065. {
  4066. sendAuthorizeRequest(0);
  4067. }
  4068. //==========================================
  4069. // Charger start transaction
  4070. //==========================================
  4071. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4072. {
  4073. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4074. sendStartTransactionRequest(gun_index);
  4075. refreshStartTimer(&clientTime.StartTransaction);
  4076. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4077. storeTempStopTransaction(gun_index);
  4078. }
  4079. //==========================================
  4080. // Charger stop transaction
  4081. //==========================================
  4082. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4083. {
  4084. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4085. sendStopTransactionRequest(gun_index);
  4086. OCPP_updatePeriodEnergy(gun_index);
  4087. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4088. refreshStartTimer(&clientTime.StopTransaction);
  4089. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4090. }
  4091. //==========================================
  4092. // Charger status report
  4093. //==========================================
  4094. //--- Check Mode Change ---//
  4095. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4097. {
  4098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4099. {
  4100. tempIndex = ((gun_index==2) ? 1: 0);
  4101. }
  4102. else
  4103. {
  4104. tempIndex = gun_index;
  4105. }
  4106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4107. {
  4108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4109. {
  4110. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4111. {
  4112. // Sent unplug message for California pricing logic
  4113. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4114. {
  4115. uint8_t ts[20];
  4116. getNowDatetime(ts);
  4117. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4118. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4119. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4120. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4121. }
  4122. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4123. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4124. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4126. {
  4127. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4128. if((access(filenmae,F_OK))!=-1)
  4129. {
  4130. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4131. sprintf(str,"rm -f %s",filenmae);
  4132. system(str);
  4133. }
  4134. }
  4135. }
  4136. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4137. #if 1 // for TempStopTransaction
  4138. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4139. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4140. {
  4141. checkTempStopTransaction(gun_index);
  4142. }
  4143. #endif
  4144. }
  4145. }
  4146. }
  4147. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4148. {
  4149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4150. {
  4151. tempIndex = ((gun_index==2) ? 1: 0);
  4152. }
  4153. else
  4154. {
  4155. tempIndex = gun_index;
  4156. }
  4157. for (int index = 0; index < CCS_QUANTITY; index++)
  4158. {
  4159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4160. {
  4161. if((SystemInitial > 0) || (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]*/ )
  4162. {
  4163. // Sent unplug message for California pricing logic
  4164. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4165. {
  4166. uint8_t ts[20];
  4167. getNowDatetime(ts);
  4168. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4169. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4170. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4171. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4172. }
  4173. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4174. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4176. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4177. {
  4178. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4179. if((access(filenmae,F_OK))!=-1)
  4180. {
  4181. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4182. sprintf(str,"rm -f %s",filenmae);
  4183. system(str);
  4184. }
  4185. }
  4186. }
  4187. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4188. #if 1 // for TempStopTransaction
  4189. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4190. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4191. {
  4192. checkTempStopTransaction(gun_index);
  4193. }
  4194. #endif
  4195. }
  4196. }
  4197. }
  4198. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4199. {
  4200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4201. {
  4202. tempIndex = ((gun_index==2) ? 1: 0);
  4203. }
  4204. else
  4205. {
  4206. tempIndex = gun_index;
  4207. }
  4208. for (int index = 0; index < GB_QUANTITY; index++)
  4209. {
  4210. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4211. {
  4212. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4213. {
  4214. // Sent unplug message for California pricing logic
  4215. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4216. {
  4217. uint8_t ts[20];
  4218. getNowDatetime(ts);
  4219. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4220. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4221. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4222. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4223. }
  4224. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4225. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4226. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4227. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4228. {
  4229. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4230. if((access(filenmae,F_OK))!=-1)
  4231. {
  4232. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4233. sprintf(str,"rm -f %s",filenmae);
  4234. system(str);
  4235. }
  4236. }
  4237. }
  4238. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4239. #if 1 // for TempStopTransaction
  4240. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4241. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4242. {
  4243. checkTempStopTransaction(gun_index);
  4244. }
  4245. #endif
  4246. }
  4247. }
  4248. }
  4249. else if(gunType[gun_index] == GUN_TYPE_DO)
  4250. {
  4251. tempIndex = gun_index;
  4252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4255. {
  4256. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4257. {
  4258. // Sent unplug message for California pricing logic
  4259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4260. {
  4261. uint8_t ts[20];
  4262. getNowDatetime(ts);
  4263. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4264. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4265. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4266. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4267. }
  4268. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4269. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4270. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4271. 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
  4272. {
  4273. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4274. if((access(filenmae,F_OK))!=-1)
  4275. {
  4276. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4277. sprintf(str,"rm -f %s",filenmae);
  4278. system(str);
  4279. }
  4280. }
  4281. }
  4282. 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);
  4283. #if 1 // for TempStopTransaction
  4284. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4285. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4286. {
  4287. checkTempStopTransaction(gun_index);
  4288. }
  4289. #endif
  4290. }
  4291. }
  4292. }
  4293. else
  4294. {
  4295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4296. {
  4297. tempIndex = 2;
  4298. }
  4299. else
  4300. {
  4301. tempIndex = gun_index;
  4302. }
  4303. for (int index = 0; index < AC_QUANTITY; index++)
  4304. {
  4305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4306. {
  4307. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4308. {
  4309. // Sent unplug message for California pricing logic
  4310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4311. {
  4312. uint8_t ts[20];
  4313. getNowDatetime(ts);
  4314. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4315. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4316. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4317. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4318. }
  4319. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4320. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4321. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4322. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4323. {
  4324. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4325. if((access(filenmae,F_OK))!=-1)
  4326. {
  4327. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4328. sprintf(str,"rm -f %s",filenmae);
  4329. system(str);
  4330. }
  4331. }
  4332. }
  4333. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4334. #if 1 // for TempStopTransaction
  4335. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4336. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4337. {
  4338. checkTempStopTransaction(gun_index);
  4339. }
  4340. #endif
  4341. }
  4342. }// END
  4343. }
  4344. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4345. (
  4346. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4347. )
  4348. )
  4349. {
  4350. if(SystemInitial > 0)
  4351. SystemInitial -= 1;
  4352. sendStatusNotificationRequest(gun_index);
  4353. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4354. }
  4355. //==============================================
  4356. // CSU Trigger Smart Charging Profile
  4357. //==============================================
  4358. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4359. {
  4360. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4361. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4362. }
  4363. //==============================================
  4364. // Meter report
  4365. //==============================================
  4366. // Trigger MeterValue
  4367. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4368. {
  4369. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4370. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4371. }
  4372. // Clock-aligned Meter value
  4373. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4374. {
  4375. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4376. reqClockAlignMeter[gun_index] = 0;
  4377. }
  4378. // Sample period MeterValue
  4379. 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))))
  4380. {
  4381. //check Transaction active
  4382. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4385. {
  4386. tempIndex = ((gun_index==2) ? 1: 0);
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4393. {
  4394. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4395. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4398. {
  4399. reqSampleMeter[gun_index] = 1;
  4400. }
  4401. }
  4402. }// End for CHAdeMO
  4403. }
  4404. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4405. {
  4406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. for (int index = 0; index < CCS_QUANTITY; index++)
  4415. {
  4416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4417. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4420. {
  4421. reqSampleMeter[gun_index] = 1;
  4422. }
  4423. }
  4424. } // End for CCS
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4429. {
  4430. tempIndex = ((gun_index==2) ? 1: 0);
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < GB_QUANTITY; index++)
  4437. {
  4438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4439. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4440. {
  4441. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4442. {
  4443. reqSampleMeter[gun_index] = 1;
  4444. }
  4445. }
  4446. }// End for GB
  4447. }
  4448. else if(gunType[gun_index] == GUN_TYPE_DO)
  4449. {
  4450. tempIndex = gun_index;
  4451. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4452. {
  4453. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4454. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4455. {
  4456. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4457. {
  4458. reqSampleMeter[gun_index] = 1;
  4459. }
  4460. }
  4461. }
  4462. }
  4463. else
  4464. {
  4465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4466. {
  4467. tempIndex = 2;
  4468. }
  4469. else
  4470. {
  4471. tempIndex = gun_index;
  4472. }
  4473. for (int index = 0; index < AC_QUANTITY; index++)
  4474. {
  4475. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4476. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4477. {
  4478. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4479. {
  4480. reqSampleMeter[gun_index] = 1;
  4481. }
  4482. }
  4483. }//End for AC
  4484. }
  4485. if(reqSampleMeter[gun_index] == 1)
  4486. {
  4487. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4488. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4489. storeTempStopTransaction(gun_index);
  4490. reqSampleMeter[gun_index] = 0;
  4491. }
  4492. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4493. }
  4494. //==============================================
  4495. // Check Connector reserved
  4496. //==============================================
  4497. //===============================
  4498. // Check if Reserve is expired
  4499. //===============================
  4500. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4501. {
  4502. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4503. {
  4504. DEBUG_INFO("reserve expired.\n");
  4505. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4506. }
  4507. }//END OF Check if Reserve is expired
  4508. //==========================================
  4509. // csu trigger FirmwareStatusNotificationReq
  4510. //==========================================
  4511. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4512. {
  4513. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4514. }
  4515. //==========================================
  4516. // csu trigger DiagnosticsStatusNotificationReq
  4517. //==========================================
  4518. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4519. {
  4520. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4521. }
  4522. //==========================================
  4523. // csu trigger CancelReservationConf
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4526. {
  4527. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4528. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4529. }
  4530. //==========================================
  4531. // csu trigger ChangeAvailabilityConf
  4532. //==========================================
  4533. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4534. {
  4535. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4536. }
  4537. //==========================================
  4538. // csu trigger UnlockConnectorConf
  4539. //==========================================
  4540. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4541. {
  4542. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4543. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4544. }
  4545. //==========================================
  4546. // csu trigger ReserveNowConf
  4547. //==========================================
  4548. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4549. {
  4550. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4551. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4552. }
  4553. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4554. {
  4555. sendSignCertificateRequest();
  4556. }
  4557. }
  4558. }
  4559. //==========================================
  4560. // send request routine
  4561. //==========================================
  4562. int sendAuthorizeRequest(int gun_index)
  4563. {
  4564. mtrace();
  4565. int result = FAIL;
  4566. char message[100]={0};
  4567. char guid[37];
  4568. char tempdata[65]={0};
  4569. DEBUG_INFO("sendAuthorizeRequest...\n");
  4570. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4571. //Local Authorize
  4572. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4573. {
  4574. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4575. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4576. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4577. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4578. result = PASS;
  4579. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4580. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4581. authorizeRetryTimes = 0;
  4582. return result;
  4583. }
  4584. 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))||
  4585. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4586. {
  4587. // Query from cache
  4588. DEBUG_INFO("Authorize from cache.\n");
  4589. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4590. // Query from list
  4591. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4592. {
  4593. DEBUG_INFO("Authorize from list.\n");
  4594. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4595. }
  4596. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4597. {
  4598. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4599. {
  4600. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4601. }
  4602. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4603. {
  4604. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4605. }
  4606. if(!GetOcppConnStatus())
  4607. {
  4608. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4609. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4610. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4611. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4612. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4613. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4614. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4615. authorizeRetryTimes = 0;
  4616. return result;
  4617. }
  4618. }
  4619. else
  4620. {
  4621. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4622. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4623. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4624. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4625. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4626. else
  4627. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4628. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4629. result = PASS;
  4630. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4631. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4632. authorizeRetryTimes = 0;
  4633. return result;
  4634. }
  4635. }
  4636. //initialize struct Authorize
  4637. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4638. //get data from shared memory
  4639. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4640. random_uuid(guid);
  4641. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4642. LWS_Send(message);
  4643. sprintf(tempdata, "Authorize,%d", gun_index);
  4644. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4645. {
  4646. result = PASS;
  4647. DEBUG_INFO("Authorize mapItem pass\n");
  4648. }
  4649. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4650. return result;
  4651. }
  4652. int sendBootNotificationRequest(void)
  4653. {
  4654. mtrace();
  4655. int result = FAIL;
  4656. char message[500]={0}, payload[700]={0};
  4657. char guid[37]={0};
  4658. char tempdata[65]={0};
  4659. // Fill BootNotification fields
  4660. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4661. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4662. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4663. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4664. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4665. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4666. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4667. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4668. ShmOCPP16Data->ChargeBoxId
  4669. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4670. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4671. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4672. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4673. ,ShmOCPP16Data->BootNotification.CpIccid
  4674. ,ShmOCPP16Data->BootNotification.CpImsi);
  4675. random_uuid(guid);
  4676. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4677. LWS_Send(message);
  4678. sprintf(tempdata, "BootNotification,0");
  4679. 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*/)
  4680. {
  4681. result = PASS;
  4682. }
  4683. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4684. strcpy(queuedata,message);
  4685. return result;
  4686. }
  4687. int sendDataTransferRequest(int gun_index)
  4688. {
  4689. mtrace();
  4690. char message[1000]={0};
  4691. char guid[37]={0};
  4692. char tempdata[65]={0};
  4693. int result = FAIL;
  4694. random_uuid(guid);
  4695. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4696. MESSAGE_TYPE_CALL,
  4697. guid,
  4698. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4699. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4700. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4701. LWS_Send(message);
  4702. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4703. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4704. {
  4705. result = PASS;
  4706. DEBUG_INFO("DataTransfer mapItem pass\n");
  4707. }
  4708. return result;
  4709. }
  4710. int sendDiagnosticsStatusNotificationRequest(char *status)
  4711. {
  4712. mtrace();
  4713. int result = FAIL;
  4714. char message[110]={0};
  4715. char guid[37]={0};
  4716. char tempdata[65]={0};
  4717. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4718. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4719. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4720. random_uuid(guid);
  4721. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4722. LWS_SendNow(message);
  4723. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4724. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4725. {
  4726. result = PASS;
  4727. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4728. }
  4729. //#ifdef SystemLogMessage
  4730. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4731. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4732. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4733. //#endif
  4734. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4735. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4736. //record status
  4737. if(strcmp(status,"Idle")==0)
  4738. {
  4739. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4740. }
  4741. else if(strcmp(status,"Uploaded")==0)
  4742. {
  4743. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4744. }
  4745. else if(strcmp(status,"UploadFailed")==0)
  4746. {
  4747. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4748. }
  4749. else if(strcmp(status,"Uploading")==0)
  4750. {
  4751. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4752. }
  4753. return result;
  4754. }
  4755. int sendFirmwareStatusNotificationRequest(char *status)
  4756. {
  4757. mtrace();
  4758. int result = FAIL;
  4759. char message[110]={0};
  4760. char guid[37]={0};
  4761. char tempdata[65]={0};
  4762. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4763. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4764. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4765. random_uuid(guid);
  4766. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4767. LWS_SendNow(message);
  4768. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4769. 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*/)
  4770. {
  4771. result = PASS;
  4772. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4773. }
  4774. //#ifdef SystemLogMessage
  4775. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4776. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4777. //#endif
  4778. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4779. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4780. //record status
  4781. if(strcmp(status,"Downloaded")==0)
  4782. {
  4783. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4784. }
  4785. else if(strcmp(status,"DownloadFailed")==0)
  4786. {
  4787. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4788. }
  4789. else if(strcmp(status,"Downloading")==0)
  4790. {
  4791. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4792. }
  4793. else if(strcmp(status,"Idle")==0)
  4794. {
  4795. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4796. }
  4797. else if(strcmp(status,"InstallationFailed")==0)
  4798. {
  4799. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4800. }
  4801. else if(strcmp(status,"Installing")==0)
  4802. {
  4803. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4804. }
  4805. else if(strcmp(status,"Installed")==0)
  4806. {
  4807. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4808. }
  4809. return result;
  4810. }
  4811. int sendHeartbeatRequest(int gun_index)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. char message[80]={0};
  4816. char guid[37]={0};
  4817. char tempdata[65]={0};
  4818. random_uuid(guid);
  4819. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4820. , MESSAGE_TYPE_CALL
  4821. , guid );
  4822. LWS_Send(message);
  4823. sprintf(tempdata, "Heartbeat,%d", 0);
  4824. 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*/)
  4825. {
  4826. result = PASS;
  4827. }
  4828. return result;
  4829. }
  4830. int sendStartTransactionRequest(int gun_index)
  4831. {
  4832. mtrace();
  4833. int result = FAIL;
  4834. char message[250]={0};
  4835. char guid[37]={0};
  4836. struct timeval tmnow;
  4837. struct tm *tm;
  4838. char buf[28];//, usec_buf[6];
  4839. char tempdata[65]={0};
  4840. int tempIndex = 0;
  4841. DEBUG_INFO("sendStartTransactionRequest...\n");
  4842. gettimeofday(&tmnow, NULL);
  4843. time_t t;
  4844. t = time(NULL);
  4845. /*UTC time and date*/
  4846. tm = gmtime(&t);
  4847. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4848. #if 0 // remove temporally
  4849. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4850. strcat(buf,".");
  4851. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4852. strcat(buf,usec_buf);
  4853. #endif
  4854. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4855. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4856. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4857. // clear StartTransaction Response
  4858. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4859. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4860. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4861. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4862. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4865. {
  4866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4867. {
  4868. tempIndex = ((gun_index==2) ? 1: 0);
  4869. }
  4870. else
  4871. {
  4872. tempIndex = gun_index;
  4873. }
  4874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4875. {
  4876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4877. {
  4878. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4879. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4880. }
  4881. }
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < CCS_QUANTITY; index++)
  4894. {
  4895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4896. {
  4897. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4898. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4899. }
  4900. }
  4901. }
  4902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4903. {
  4904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4905. {
  4906. tempIndex = ((gun_index==2) ? 1: 0);
  4907. }
  4908. else
  4909. {
  4910. tempIndex = gun_index;
  4911. }
  4912. for (int index = 0; index < GB_QUANTITY; index++)
  4913. {
  4914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4915. {
  4916. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4917. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4918. }
  4919. }
  4920. }
  4921. else if(gunType[gun_index] == GUN_TYPE_DO)
  4922. {
  4923. tempIndex = gun_index;
  4924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4927. {
  4928. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4929. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4930. }
  4931. }
  4932. }
  4933. else
  4934. {
  4935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4936. {
  4937. tempIndex = 2;
  4938. }
  4939. else
  4940. {
  4941. tempIndex = gun_index;
  4942. }
  4943. for (int index = 0; index < AC_QUANTITY; index++)
  4944. {
  4945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4946. {
  4947. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4948. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4949. }
  4950. }
  4951. }
  4952. random_uuid(guid);
  4953. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4954. {
  4955. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4956. , gun_index +1
  4957. , MESSAGE_TYPE_CALL
  4958. , guid
  4959. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4960. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4961. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4962. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4963. }
  4964. else
  4965. {
  4966. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4967. , gun_index +1
  4968. , MESSAGE_TYPE_CALL
  4969. , guid
  4970. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4971. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4972. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4973. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4974. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4975. }
  4976. #if 1
  4977. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4978. 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*/)
  4979. {
  4980. result = PASS;
  4981. }
  4982. #endif
  4983. strcpy(queuedata, message);
  4984. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4985. OCPP_insert_transaction_msg(YES, queuedata);
  4986. return result;
  4987. }
  4988. int sendStatusNotificationRequest(int gun_index)
  4989. {
  4990. mtrace();
  4991. int result = FAIL;
  4992. char message[600]={0};
  4993. char guid[37];
  4994. int currentStatus = 0;
  4995. struct timeval tmnow;
  4996. struct tm *tm;
  4997. char buf[28];//, usec_buf[6];
  4998. char tempdata[65]={0};
  4999. int tempIndex = 0;
  5000. uint8_t isStateChanged = TRUE;
  5001. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5002. gettimeofday(&tmnow, NULL);
  5003. time_t t;
  5004. t = time(NULL);
  5005. /*UTC time and date*/
  5006. tm = gmtime(&t);
  5007. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5008. #if 0 // remove temporally
  5009. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5010. strcat(buf,".");
  5011. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5012. strcat(buf,usec_buf);
  5013. #endif
  5014. //printf("%s",buf);
  5015. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5016. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5017. // it's option
  5018. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5019. /*
  5020. enum _SYSTEM_STATUS
  5021. {
  5022. S_BOOTING = 0,
  5023. S_IDLE, = 1
  5024. S_AUTHORIZING, =2
  5025. S_REASSIGN_CHECK, =3
  5026. S_REASSIGN, =4
  5027. S_PRECHARGE, =5
  5028. S_PREPARING_FOR_EV, =6
  5029. S_PREPARING_FOR_EVSE, =7
  5030. S_CHARGING, =8
  5031. S_TERMINATING, =9
  5032. S_COMPLETE, =10
  5033. S_ALARM, =11
  5034. S_FAULT =12
  5035. }
  5036. */
  5037. //check Transaction active
  5038. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5040. {
  5041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5042. {
  5043. tempIndex = ((gun_index==2) ? 1: 0);
  5044. }
  5045. else
  5046. {
  5047. tempIndex = gun_index;
  5048. }
  5049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5050. {
  5051. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5052. {
  5053. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5054. {
  5055. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5056. {
  5057. currentStatus = Preparing; //OCPP Status: Preparing
  5058. }
  5059. else
  5060. {
  5061. currentStatus = Available; //OCPP Status: Available
  5062. }
  5063. }
  5064. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5065. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5066. ) //S_PRECHARGE
  5067. {
  5068. currentStatus = Preparing; //OCPP Status: Preparing
  5069. }
  5070. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5071. {
  5072. currentStatus = Charging; //OCPP Status: Charging
  5073. }
  5074. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5075. {
  5076. currentStatus = Finishing; //OCPP Status: Finishing
  5077. }
  5078. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5079. {
  5080. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5081. }
  5082. 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
  5083. {
  5084. currentStatus = Unavailable; //OCPP Status: Unavailable
  5085. }
  5086. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5087. {
  5088. currentStatus = Faulted; //OCPP Status: Faulted
  5089. }
  5090. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5091. {
  5092. currentStatus = Reserved; //OCPP Status: Reserved
  5093. }
  5094. } //end of the same index
  5095. }//end of for CHAdeMO_QUANTITY
  5096. }
  5097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5098. {
  5099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5100. {
  5101. tempIndex = ((gun_index==2) ? 1: 0);
  5102. }
  5103. else
  5104. {
  5105. tempIndex = gun_index;
  5106. }
  5107. for (int index = 0; index < CCS_QUANTITY; index++)
  5108. {
  5109. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5110. {
  5111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5112. {
  5113. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5114. {
  5115. currentStatus = Preparing; //OCPP Status: Preparing
  5116. }
  5117. else
  5118. {
  5119. currentStatus = Available; //OCPP Status: Available
  5120. }
  5121. }
  5122. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5123. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5124. ) //S_PRECHARGE
  5125. {
  5126. currentStatus = Preparing; //OCPP Status: Preparing
  5127. }
  5128. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5129. {
  5130. currentStatus = Charging; //OCPP Status: Charging
  5131. }
  5132. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5133. {
  5134. currentStatus = Finishing; //OCPP Status: Finishing
  5135. }
  5136. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5137. {
  5138. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5139. }
  5140. 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
  5141. {
  5142. currentStatus = Unavailable; //OCPP Status : Unavailable
  5143. }
  5144. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5145. {
  5146. currentStatus = Faulted; //OCPP Status: Faulted
  5147. }
  5148. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5149. {
  5150. currentStatus = Reserved; //OCPP Status: Reserved
  5151. }
  5152. } //end of the same index
  5153. } // end of for CCS_QUANTITY
  5154. }
  5155. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5156. {
  5157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5158. {
  5159. tempIndex = ((gun_index==2) ? 1: 0);
  5160. }
  5161. else
  5162. {
  5163. tempIndex = gun_index;
  5164. }
  5165. for (int index = 0; index < GB_QUANTITY; index++)
  5166. {
  5167. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5170. {
  5171. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5172. {
  5173. currentStatus = Preparing; //OCPP Status: Preparing
  5174. }
  5175. else
  5176. {
  5177. currentStatus = Available; //OCPP Status: Available
  5178. }
  5179. }
  5180. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5181. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5182. ) //S_PRECHARGE
  5183. {
  5184. currentStatus = Preparing; //OCPP Status: Preparing
  5185. }
  5186. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5187. {
  5188. currentStatus = Charging; //OCPP Status: Charging
  5189. }
  5190. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5191. {
  5192. currentStatus = Finishing; //OCPP Status: Finishing
  5193. }
  5194. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5195. {
  5196. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5197. }
  5198. 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
  5199. {
  5200. currentStatus = Unavailable; //OCPP Status: Unavailable
  5201. }
  5202. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5203. {
  5204. currentStatus = Faulted; //OCPP Status: Faulted
  5205. }
  5206. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5207. {
  5208. currentStatus = Reserved; //OCPP Status: Reserved
  5209. }
  5210. } //end of the same index
  5211. } // end of for GB_QUANTITY
  5212. }
  5213. else if(gunType[gun_index] == GUN_TYPE_DO)
  5214. {
  5215. tempIndex = gun_index;
  5216. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5217. {
  5218. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5219. {
  5220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5221. {
  5222. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5223. {
  5224. currentStatus = Preparing; //OCPP Status: Preparing
  5225. }
  5226. else
  5227. {
  5228. currentStatus = Available; //OCPP Status: Available
  5229. }
  5230. }
  5231. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5232. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5233. ) //S_PRECHARGE
  5234. {
  5235. currentStatus = Preparing; //OCPP Status: Preparing
  5236. }
  5237. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5238. {
  5239. currentStatus = Charging; //OCPP Status: Charging
  5240. }
  5241. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5242. {
  5243. currentStatus = Finishing; //OCPP Status: Finishing
  5244. }
  5245. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5246. {
  5247. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5248. }
  5249. 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
  5250. {
  5251. currentStatus = Unavailable; //OCPP Status: Unavailable
  5252. }
  5253. 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
  5254. {
  5255. currentStatus = Faulted; //OCPP Status: Faulted
  5256. }
  5257. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5258. {
  5259. currentStatus = Reserved; //OCPP Status: Reserved
  5260. }
  5261. } //end of the same index
  5262. }
  5263. }
  5264. else
  5265. {
  5266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5267. {
  5268. tempIndex = 2;
  5269. }
  5270. else
  5271. {
  5272. tempIndex = gun_index;
  5273. }
  5274. for (int index = 0; index < AC_QUANTITY; index++)
  5275. {
  5276. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5279. {
  5280. 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))
  5281. {
  5282. currentStatus = Preparing; //OCPP Status: Preparing
  5283. }
  5284. else
  5285. {
  5286. currentStatus = Available; //OCPP Status: Available
  5287. }
  5288. }
  5289. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5290. {
  5291. currentStatus = Preparing; //OCPP Status: Preparing
  5292. }
  5293. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5294. {
  5295. currentStatus = Charging; //OCPP Status: Charging
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5298. {
  5299. currentStatus = Finishing; //OCPP Status: Finishing
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5302. {
  5303. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5304. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5305. else
  5306. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5307. }
  5308. 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
  5309. {
  5310. currentStatus = Unavailable; //OCPP Status: Unavailable
  5311. }
  5312. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5313. {
  5314. currentStatus = Faulted; //OCPP Status: Faulted
  5315. }
  5316. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5317. {
  5318. currentStatus = Reserved; //OCPP Status: Reserved
  5319. }
  5320. }//end of the same index
  5321. }//end of for AC_QUANTITY
  5322. }
  5323. //it's option
  5324. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5325. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5326. {
  5327. isStateChanged = FALSE;
  5328. }
  5329. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5330. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5331. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5332. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5333. random_uuid(guid);
  5334. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5335. , MESSAGE_TYPE_CALL
  5336. , guid
  5337. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5338. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5339. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5340. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5341. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5342. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5343. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5344. if((server_sign == TRUE) && isStateChanged)
  5345. {
  5346. LWS_Send(message);
  5347. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5348. 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*/)
  5349. {
  5350. //DEBUG_ERROR("statusNotification mapitem pass");
  5351. result = PASS;
  5352. }
  5353. }
  5354. else
  5355. {
  5356. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5357. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5358. result = PASS;
  5359. }
  5360. return result;
  5361. }
  5362. int sendStopTransactionRequest(int gun_index)
  5363. {
  5364. mtrace();
  5365. int result = FAIL;
  5366. //char message[1500]={0};
  5367. char guid[37]={0};
  5368. char tempdata[65]={0};
  5369. int tempIndex = 0;
  5370. char TempStopTransaction[256];
  5371. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5372. //int idx_sample=0;
  5373. DEBUG_INFO("sendStopTransactionRequest \n");
  5374. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5375. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5376. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5379. {
  5380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5381. {
  5382. tempIndex = ((gun_index==2) ? 1: 0);
  5383. }
  5384. else
  5385. {
  5386. tempIndex = gun_index;
  5387. }
  5388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5389. {
  5390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5391. {
  5392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5393. }
  5394. }// END OF CHAdeMO_QUANTITY
  5395. }
  5396. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5397. {
  5398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5399. {
  5400. tempIndex = ((gun_index==2) ? 1: 0);
  5401. }
  5402. else
  5403. {
  5404. tempIndex = gun_index;
  5405. }
  5406. for (int index = 0; index < CCS_QUANTITY; index++)
  5407. {
  5408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5409. {
  5410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5411. }
  5412. }// END OF CCS_QUANTITY
  5413. }
  5414. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5415. {
  5416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5417. {
  5418. tempIndex = ((gun_index==2) ? 1: 0);
  5419. }
  5420. else
  5421. {
  5422. tempIndex = gun_index;
  5423. }
  5424. for (int index = 0; index < GB_QUANTITY; index++)
  5425. {
  5426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5427. {
  5428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5429. }
  5430. }// END OF GB_QUANTITY
  5431. }
  5432. else if(gunType[gun_index] == GUN_TYPE_DO)
  5433. {
  5434. tempIndex = gun_index;
  5435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5436. {
  5437. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5438. {
  5439. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5440. }
  5441. }// END OF GB_QUANTITY
  5442. }
  5443. else
  5444. {
  5445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5446. {
  5447. tempIndex = 2;
  5448. }
  5449. else
  5450. {
  5451. tempIndex = gun_index;
  5452. }
  5453. for (int index = 0; index < AC_QUANTITY; index++)
  5454. {
  5455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5456. {
  5457. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5458. }
  5459. }// END OF AC_QUANTITY
  5460. }
  5461. //====================================== Stop Transaction Time =====================================================
  5462. struct timeval tmnow;
  5463. struct tm *tm;
  5464. char buf[28];//, usec_buf[6];
  5465. gettimeofday(&tmnow, NULL);
  5466. time_t t;
  5467. t = time(NULL);
  5468. /*UTC time and date*/
  5469. tm = gmtime(&t);
  5470. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5472. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5473. random_uuid(guid);
  5474. /***********************************transactionData******************************************************/
  5475. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5477. //=================================
  5478. // Transaction_Begin
  5479. //=================================
  5480. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5481. {
  5482. //============================================ Energy.Active.Import.Interval ================================
  5483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5486. 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*/]);
  5487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5488. 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))
  5489. {
  5490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5491. }
  5492. else
  5493. {
  5494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5495. }
  5496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5498. }
  5499. //=================================
  5500. // Transaction_End
  5501. //=================================
  5502. // ================================= Current.Import L1 ===============================================
  5503. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5504. {
  5505. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5506. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5507. {
  5508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5509. {
  5510. tempIndex = ((gun_index==2) ? 1: 0);
  5511. }
  5512. else
  5513. {
  5514. tempIndex = gun_index;
  5515. }
  5516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5517. {
  5518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5519. {
  5520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5521. }
  5522. }// End of for CHAdeMO_QUANTITY
  5523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5524. }
  5525. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5526. {
  5527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5528. {
  5529. tempIndex = ((gun_index==2) ? 1: 0);
  5530. }
  5531. else
  5532. {
  5533. tempIndex = gun_index;
  5534. }
  5535. for (int index = 0; index < CCS_QUANTITY; index++)
  5536. {
  5537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5538. {
  5539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5540. }
  5541. }// End of for CCS_QUANTITY
  5542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5543. }
  5544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5545. {
  5546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5547. {
  5548. tempIndex = ((gun_index==2) ? 1: 0);
  5549. }
  5550. else
  5551. {
  5552. tempIndex = gun_index;
  5553. }
  5554. for (int index = 0; index < GB_QUANTITY; index++)
  5555. {
  5556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5557. {
  5558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5559. }
  5560. }// End of for GB_QUANTITY
  5561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5562. }
  5563. else if(gunType[gun_index] == GUN_TYPE_DO)
  5564. {
  5565. tempIndex = gun_index;
  5566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5567. {
  5568. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5569. {
  5570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5571. }
  5572. }
  5573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5574. }
  5575. else
  5576. {
  5577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5578. {
  5579. tempIndex = 2;
  5580. }
  5581. else
  5582. {
  5583. tempIndex = gun_index;
  5584. }
  5585. for (int index = 0; index < AC_QUANTITY; index++)
  5586. {
  5587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5588. {
  5589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5590. }
  5591. }// End of for AC_QUANTITY
  5592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5593. }
  5594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5599. }
  5600. // ================================= Energy.Active.Import.Interval ==============================================
  5601. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5602. {
  5603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5605. {
  5606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5607. {
  5608. tempIndex = ((gun_index==2) ? 1: 0);
  5609. }
  5610. else
  5611. {
  5612. tempIndex = gun_index;
  5613. }
  5614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5615. {
  5616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5617. {
  5618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5619. }
  5620. }// END OF CHAdeMO_QUANTITY
  5621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5622. }
  5623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5624. {
  5625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5626. {
  5627. tempIndex = ((gun_index==2) ? 1: 0);
  5628. }
  5629. else
  5630. {
  5631. tempIndex = gun_index;
  5632. }
  5633. for (int index = 0; index < CCS_QUANTITY; index++)
  5634. {
  5635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5636. {
  5637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5638. }
  5639. }// END OF CCS_QUANTITY
  5640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5641. }
  5642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5643. {
  5644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5645. {
  5646. tempIndex = ((gun_index==2) ? 1: 0);
  5647. }
  5648. else
  5649. {
  5650. tempIndex = gun_index;
  5651. }
  5652. for (int index = 0; index < GB_QUANTITY; index++)
  5653. {
  5654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5655. {
  5656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5657. }
  5658. }// END OF GB_QUANTITY
  5659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5660. }
  5661. else if(gunType[gun_index] == GUN_TYPE_DO)
  5662. {
  5663. tempIndex = gun_index;
  5664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5665. {
  5666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5667. {
  5668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5669. }
  5670. }
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5672. }
  5673. else
  5674. {
  5675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5676. {
  5677. tempIndex = 2;
  5678. }
  5679. else
  5680. {
  5681. tempIndex = gun_index;
  5682. }
  5683. for (int index = 0; index < AC_QUANTITY; index++)
  5684. {
  5685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5686. {
  5687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5688. }
  5689. }// END OF AC_QUANTITY
  5690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5691. }
  5692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5697. }
  5698. //=================================== Power.Active.Import ==================================================
  5699. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5700. {
  5701. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5702. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5703. {
  5704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5705. {
  5706. tempIndex = ((gun_index==2) ? 1: 0);
  5707. }
  5708. else
  5709. {
  5710. tempIndex = gun_index;
  5711. }
  5712. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5713. {
  5714. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5715. {
  5716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5717. }
  5718. } // End for CHAdeMO_QUANTITY
  5719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5720. }
  5721. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5722. {
  5723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5724. {
  5725. tempIndex = ((gun_index==2) ? 1: 0);
  5726. }
  5727. else
  5728. {
  5729. tempIndex = gun_index;
  5730. }
  5731. for (int index = 0; index < CCS_QUANTITY; index++)
  5732. {
  5733. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5734. {
  5735. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5736. }
  5737. } // END for CCS_QUANTITY
  5738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5739. }
  5740. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5741. {
  5742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5743. {
  5744. tempIndex = ((gun_index==2) ? 1: 0);
  5745. }
  5746. else
  5747. {
  5748. tempIndex = gun_index;
  5749. }
  5750. for (int index = 0; index < GB_QUANTITY; index++)
  5751. {
  5752. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5753. {
  5754. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5755. }
  5756. }// END for GB_QUANTITY
  5757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5758. }
  5759. else if(gunType[gun_index] == GUN_TYPE_DO)
  5760. {
  5761. tempIndex = gun_index;
  5762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5763. {
  5764. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5765. {
  5766. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5767. }
  5768. }
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5770. }
  5771. else
  5772. {
  5773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5774. {
  5775. tempIndex = 2;
  5776. }
  5777. else
  5778. {
  5779. tempIndex = gun_index;
  5780. }
  5781. for (int index = 0; index < AC_QUANTITY; index++)
  5782. {
  5783. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5784. {
  5785. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5786. }
  5787. } // END for AC_QUANTITY
  5788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5789. }
  5790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5795. }
  5796. //============================ Voltage L1 ====================================
  5797. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5798. {
  5799. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5800. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5801. {
  5802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5803. {
  5804. tempIndex = ((gun_index==2) ? 1: 0);
  5805. }
  5806. else
  5807. {
  5808. tempIndex = gun_index;
  5809. }
  5810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5811. {
  5812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5813. {
  5814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5815. }
  5816. } // END OF FOR CHAdeMO_QUANTITY
  5817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5818. }
  5819. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5820. {
  5821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5822. {
  5823. tempIndex = ((gun_index==2) ? 1: 0);
  5824. }
  5825. else
  5826. {
  5827. tempIndex = gun_index;
  5828. }
  5829. for (int index = 0; index < CCS_QUANTITY; index++)
  5830. {
  5831. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5832. {
  5833. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5834. }
  5835. } // END OF FOR CCS_QUANTITY
  5836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5837. }
  5838. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5839. {
  5840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5841. {
  5842. tempIndex = ((gun_index==2) ? 1: 0);
  5843. }
  5844. else
  5845. {
  5846. tempIndex = gun_index;
  5847. }
  5848. for (int index = 0; index < GB_QUANTITY; index++)
  5849. {
  5850. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5851. {
  5852. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5853. }
  5854. } // END OF FOR GB_QUANTITY
  5855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5856. }
  5857. else if(gunType[gun_index] == GUN_TYPE_DO)
  5858. {
  5859. tempIndex = gun_index;
  5860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5861. {
  5862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5863. {
  5864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5865. }
  5866. }
  5867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5868. }
  5869. else
  5870. {
  5871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5872. {
  5873. tempIndex = 2;
  5874. }
  5875. else
  5876. {
  5877. tempIndex = gun_index;
  5878. }
  5879. for (int index = 0; index < AC_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5882. {
  5883. 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
  5884. }
  5885. } // END OF FOR AC_QUANTITY
  5886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5887. }
  5888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5893. }
  5894. //====================== End SoC ================================
  5895. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5896. {
  5897. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5898. 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))
  5899. {
  5900. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5901. {
  5902. tempIndex = ((gun_index==2) ? 1: 0);
  5903. }
  5904. else
  5905. {
  5906. tempIndex = gun_index;
  5907. }
  5908. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5909. {
  5910. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5913. {
  5914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5915. }
  5916. }
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5919. {
  5920. for (int index = 0; index < CCS_QUANTITY; index++)
  5921. {
  5922. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5923. {
  5924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5925. }
  5926. }
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5929. {
  5930. for (int index = 0; index < GB_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5935. }
  5936. }
  5937. }
  5938. else if(gunType[gun_index] == GUN_TYPE_DO)
  5939. {
  5940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5945. }
  5946. }
  5947. }
  5948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5954. } // END FOR DC CASE
  5955. }
  5956. // ================================= Current.Import L2 ===============================================
  5957. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5958. {
  5959. // AC 3 phse L2 current
  5960. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5961. {
  5962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5963. {
  5964. tempIndex = 2;
  5965. }
  5966. else
  5967. {
  5968. tempIndex = gun_index;
  5969. }
  5970. for (int index = 0; index < AC_QUANTITY; index++)
  5971. {
  5972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5973. {
  5974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5975. }
  5976. }// End of for AC_QUANTITY
  5977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5978. }
  5979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5984. }
  5985. // ================================= Current.Import L3 ===============================================
  5986. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5987. {
  5988. // AC 3 phse L3 current
  5989. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5990. {
  5991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5992. {
  5993. tempIndex = 2;
  5994. }
  5995. else
  5996. {
  5997. tempIndex = gun_index;
  5998. }
  5999. for (int index = 0; index < AC_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6002. {
  6003. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6004. }
  6005. }// End of for AC_QUANTITY
  6006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6013. }
  6014. //============================ Voltage L2 ====================================
  6015. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6016. {
  6017. // AC 3 phse L2 voltage
  6018. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6021. {
  6022. tempIndex = 2;
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < AC_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6031. {
  6032. 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
  6033. }
  6034. } // END OF FOR AC_QUANTITY
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6036. }
  6037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6042. }
  6043. //============================ Voltage L3 ====================================
  6044. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6045. {
  6046. // AC 3 phse L3 voltage
  6047. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6048. {
  6049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6050. {
  6051. tempIndex = 2;
  6052. }
  6053. else
  6054. {
  6055. tempIndex = gun_index;
  6056. }
  6057. for (int index = 0; index < AC_QUANTITY; index++)
  6058. {
  6059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6060. {
  6061. 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
  6062. }
  6063. } // END OF FOR AC_QUANTITY
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6065. }
  6066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6071. }
  6072. //====================== Start SoC ================================
  6073. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6074. {
  6075. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6076. 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))
  6077. {
  6078. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6079. {
  6080. tempIndex = ((gun_index==2) ? 1: 0);
  6081. }
  6082. else
  6083. {
  6084. tempIndex = gun_index;
  6085. }
  6086. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6087. {
  6088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6089. {
  6090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6091. {
  6092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6093. }
  6094. }
  6095. }
  6096. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6097. {
  6098. for (int index = 0; index < CCS_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6101. {
  6102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6103. }
  6104. }
  6105. }
  6106. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6107. {
  6108. for (int index = 0; index < GB_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6113. }
  6114. }
  6115. }
  6116. else if(gunType[gun_index] == GUN_TYPE_DO)
  6117. {
  6118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6119. {
  6120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6121. {
  6122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6123. }
  6124. }
  6125. }
  6126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6132. } // END FOR DC CASE
  6133. }
  6134. //================================================ Message create ====================================================
  6135. json_object *StopTransaction = json_object_new_object();
  6136. json_object *transactionDatas = json_object_new_array();
  6137. json_object *sampledValues = json_object_new_array();
  6138. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6139. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6140. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6141. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6142. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6143. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6144. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6145. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6146. {
  6147. json_object *transactionData = json_object_new_object();
  6148. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6149. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6150. {
  6151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6152. {
  6153. json_object *sampledValue = json_object_new_object();
  6154. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6155. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6156. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6158. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6159. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6160. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6162. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6163. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6164. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6166. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6167. json_object_array_add(sampledValues, sampledValue);
  6168. }
  6169. }
  6170. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6171. json_object_array_add(transactionDatas, transactionData);
  6172. }
  6173. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6174. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6175. ,MESSAGE_TYPE_CALL
  6176. ,guid
  6177. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6178. json_object_put(StopTransaction);
  6179. #if 1 // for TempStopTransaction
  6180. //Delete TempStopTransaction
  6181. if((access(TempStopTransaction,F_OK))!=-1)
  6182. {
  6183. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6184. }
  6185. #endif
  6186. #if 1
  6187. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6188. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6189. {
  6190. result = PASS;
  6191. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6192. }
  6193. #endif
  6194. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6195. OCPP_insert_transaction_msg(NO, queuedata);
  6196. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6197. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6198. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6199. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6200. {
  6201. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6202. }
  6203. //for test
  6204. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6205. return result;
  6206. }
  6207. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6208. {
  6209. mtrace();
  6210. int result = FAIL;
  6211. char guid[37]={0};
  6212. char tempdata[65]={0};
  6213. int tempIndex = 0;
  6214. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6215. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6216. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6217. //set value
  6218. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6219. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6220. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6221. -1);
  6222. random_uuid(guid);
  6223. //UTC Date time
  6224. struct timeval tmnow;
  6225. struct tm *tm;
  6226. char buf[28];//, usec_buf[6];
  6227. gettimeofday(&tmnow, NULL);
  6228. time_t t;
  6229. t = time(NULL);
  6230. /*UTC time and date*/
  6231. tm = gmtime(&t);
  6232. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6234. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6235. //********************************(1)Current.Import L1************************************************/
  6236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6238. (dataType == ReadingContext_Trigger))
  6239. {
  6240. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6241. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6244. {
  6245. tempIndex = ((gun_index==2) ? 1: 0);
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6256. }
  6257. }
  6258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6259. }
  6260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6261. {
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6263. {
  6264. tempIndex = ((gun_index==2) ? 1: 0);
  6265. }
  6266. else
  6267. {
  6268. tempIndex = gun_index;
  6269. }
  6270. for (int index = 0; index < CCS_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6273. {
  6274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6275. }
  6276. }
  6277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6278. }
  6279. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6280. {
  6281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6282. {
  6283. tempIndex = ((gun_index==2) ? 1: 0);
  6284. }
  6285. else
  6286. {
  6287. tempIndex = gun_index;
  6288. }
  6289. for (int index = 0; index < GB_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6292. {
  6293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6294. }
  6295. }
  6296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6297. }
  6298. else if(gunType[gun_index] == GUN_TYPE_DO)
  6299. {
  6300. tempIndex = gun_index;
  6301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6304. {
  6305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6306. }
  6307. }
  6308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6309. }
  6310. else
  6311. {
  6312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6313. {
  6314. tempIndex = 2;
  6315. }
  6316. else
  6317. {
  6318. tempIndex = gun_index;
  6319. }
  6320. for (int index = 0; index < AC_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6323. {
  6324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6325. }
  6326. }
  6327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6328. }
  6329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6334. }
  6335. //********************************(2)Energy.Active.Import.Register ************************************************/
  6336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6338. (dataType == ReadingContext_Trigger))
  6339. {
  6340. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6341. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6344. {
  6345. tempIndex = ((gun_index==2) ? 1: 0);
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6354. {
  6355. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6356. }
  6357. }
  6358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6359. }
  6360. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6361. {
  6362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6363. {
  6364. tempIndex = ((gun_index==2) ? 1: 0);
  6365. }
  6366. else
  6367. {
  6368. tempIndex = gun_index;
  6369. }
  6370. for (int index = 0; index < CCS_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6375. }
  6376. }
  6377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < GB_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6394. }
  6395. }
  6396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6397. }
  6398. else if(gunType[gun_index] == GUN_TYPE_DO)
  6399. {
  6400. tempIndex = gun_index;
  6401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6404. {
  6405. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6406. }
  6407. }
  6408. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6409. }
  6410. else
  6411. {
  6412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6413. {
  6414. tempIndex = 2;
  6415. }
  6416. else
  6417. {
  6418. tempIndex = gun_index;
  6419. }
  6420. for (int index = 0; index < AC_QUANTITY; index++)
  6421. {
  6422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6423. {
  6424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6428. }
  6429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6434. }
  6435. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6438. (dataType == ReadingContext_Trigger))
  6439. {
  6440. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6442. {
  6443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6444. {
  6445. tempIndex = ((gun_index==2) ? 1: 0);
  6446. }
  6447. else
  6448. {
  6449. tempIndex = gun_index;
  6450. }
  6451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6454. {
  6455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6456. }
  6457. } // END OF FOR CHAdeMO_QUANTITY
  6458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6459. }
  6460. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < CCS_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6475. }
  6476. } // END OF CCS_QUANTITY
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < GB_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6494. }
  6495. } // END OF GB_QUANTITY
  6496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6497. }
  6498. else if(gunType[gun_index] == GUN_TYPE_DO)
  6499. {
  6500. tempIndex = gun_index;
  6501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6504. {
  6505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6506. }
  6507. }
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6509. }
  6510. else
  6511. {
  6512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6513. {
  6514. tempIndex = 2;
  6515. }
  6516. else
  6517. {
  6518. tempIndex = gun_index;
  6519. }
  6520. for (int index = 0; index < AC_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6525. }
  6526. }
  6527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6528. }
  6529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6534. }
  6535. //********************************(4)Power.Active.Import************************************************/
  6536. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6537. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6538. (dataType == ReadingContext_Trigger))
  6539. {
  6540. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6541. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6544. {
  6545. tempIndex = ((gun_index==2) ? 1: 0);
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6556. }
  6557. } // END OF FOR
  6558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6559. }
  6560. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6561. {
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6563. {
  6564. tempIndex = ((gun_index==2) ? 1: 0);
  6565. }
  6566. else
  6567. {
  6568. tempIndex = gun_index;
  6569. }
  6570. for (int index = 0; index < CCS_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6575. }
  6576. }
  6577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6578. }
  6579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6580. {
  6581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6582. {
  6583. tempIndex = ((gun_index==2) ? 1: 0);
  6584. }
  6585. else
  6586. {
  6587. tempIndex = gun_index;
  6588. }
  6589. for (int index = 0; index < GB_QUANTITY; index++)
  6590. {
  6591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6592. {
  6593. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6595. }
  6596. }
  6597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6598. }
  6599. else if(gunType[gun_index] == GUN_TYPE_DO)
  6600. {
  6601. tempIndex = gun_index;
  6602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6605. {
  6606. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6608. }
  6609. }
  6610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6611. }
  6612. else
  6613. {
  6614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6615. {
  6616. tempIndex = 2;
  6617. }
  6618. else
  6619. {
  6620. tempIndex = gun_index;
  6621. }
  6622. for (int index = 0; index < AC_QUANTITY; index++)
  6623. {
  6624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6625. {
  6626. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6627. }
  6628. }
  6629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6630. }
  6631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6636. }
  6637. //***********************************************(5)VOLTAGE L1******************************************************/
  6638. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6639. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6640. (dataType == ReadingContext_Trigger))
  6641. {
  6642. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6644. {
  6645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6646. {
  6647. tempIndex = ((gun_index==2) ? 1: 0);
  6648. }
  6649. else
  6650. {
  6651. tempIndex = gun_index;
  6652. }
  6653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6654. {
  6655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6656. {
  6657. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6658. }
  6659. }
  6660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6661. }
  6662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6663. {
  6664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6665. {
  6666. tempIndex = ((gun_index==2) ? 1: 0);
  6667. }
  6668. else
  6669. {
  6670. tempIndex = gun_index;
  6671. }
  6672. for (int index = 0; index < CCS_QUANTITY; index++)
  6673. {
  6674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6675. {
  6676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6677. }
  6678. }
  6679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6682. {
  6683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6684. {
  6685. tempIndex = ((gun_index==2) ? 1: 0);
  6686. }
  6687. else
  6688. {
  6689. tempIndex = gun_index;
  6690. }
  6691. for (int index = 0; index < GB_QUANTITY; index++)
  6692. {
  6693. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6694. {
  6695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6696. }
  6697. }
  6698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6699. }
  6700. else if(gunType[gun_index] == GUN_TYPE_DO)
  6701. {
  6702. tempIndex = gun_index;
  6703. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6704. {
  6705. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6706. {
  6707. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6708. }
  6709. }
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6711. }
  6712. else
  6713. {
  6714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6715. {
  6716. tempIndex = 2;
  6717. }
  6718. else
  6719. {
  6720. tempIndex = gun_index;
  6721. }
  6722. for (int index = 0; index < AC_QUANTITY; index++)
  6723. {
  6724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6725. {
  6726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6727. }
  6728. }
  6729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6730. }
  6731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6736. }
  6737. //***********************************************(6)SOC******************************************************/
  6738. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6739. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6740. (dataType == ReadingContext_Trigger))
  6741. {
  6742. 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))
  6743. {
  6744. //idx_sample=5;
  6745. //sampledValue = NULL;
  6746. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6747. {
  6748. tempIndex = ((gun_index==2) ? 1: 0);
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6755. {
  6756. //tempIndex = ((gun_index==2) ? 1: 0);
  6757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6758. {
  6759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6760. {
  6761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6762. }
  6763. }
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6766. {
  6767. //tempIndex = ((gun_index==2) ? 1: 0);
  6768. for (int index = 0; index < CCS_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6771. {
  6772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6773. }
  6774. }
  6775. }
  6776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6777. {
  6778. //tempIndex = ((gun_index==2) ? 1: 0);
  6779. for (int index = 0; index < GB_QUANTITY; index++)
  6780. {
  6781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6782. {
  6783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6784. }
  6785. }
  6786. }
  6787. else if(gunType[gun_index] == GUN_TYPE_DO)
  6788. {
  6789. //tempIndex = ((gun_index==2) ? 1: 0);
  6790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6791. {
  6792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6793. {
  6794. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6795. }
  6796. }
  6797. }
  6798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6800. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6804. }
  6805. }
  6806. //********************************(7)Current.Import L2************************************************/
  6807. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6808. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6809. (dataType == ReadingContext_Trigger))
  6810. {
  6811. // Only for AC 3 phase
  6812. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6813. {
  6814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6815. {
  6816. tempIndex = 2;
  6817. }
  6818. else
  6819. {
  6820. tempIndex = gun_index;
  6821. }
  6822. for (int index = 0; index < AC_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6825. {
  6826. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6827. }
  6828. }
  6829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6830. }
  6831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6836. }
  6837. //********************************(8)Current.Import L3************************************************/
  6838. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6839. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6840. (dataType == ReadingContext_Trigger))
  6841. {
  6842. // Only for AC 3 phase
  6843. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6844. {
  6845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6846. {
  6847. tempIndex = 2;
  6848. }
  6849. else
  6850. {
  6851. tempIndex = gun_index;
  6852. }
  6853. for (int index = 0; index < AC_QUANTITY; index++)
  6854. {
  6855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6856. {
  6857. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6858. }
  6859. }
  6860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6861. }
  6862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6867. }
  6868. //***********************************************(9)VOLTAGE L2******************************************************/
  6869. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6870. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6871. (dataType == ReadingContext_Trigger))
  6872. {
  6873. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6874. {
  6875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6876. {
  6877. tempIndex = 2;
  6878. }
  6879. else
  6880. {
  6881. tempIndex = gun_index;
  6882. }
  6883. for (int index = 0; index < AC_QUANTITY; index++)
  6884. {
  6885. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6886. {
  6887. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6888. }
  6889. }
  6890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6891. }
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6897. }
  6898. //***********************************************(10)VOLTAGE L3******************************************************/
  6899. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6900. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6901. (dataType == ReadingContext_Trigger))
  6902. {
  6903. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6904. {
  6905. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6906. {
  6907. tempIndex = 2;
  6908. }
  6909. else
  6910. {
  6911. tempIndex = gun_index;
  6912. }
  6913. for (int index = 0; index < AC_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6916. {
  6917. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6921. }
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6927. }
  6928. //***********************************************(11)Current.Offered******************************************************/
  6929. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6930. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6931. (dataType == ReadingContext_Trigger))
  6932. {
  6933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6935. {
  6936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6937. {
  6938. tempIndex = ((gun_index==2) ? 1: 0);
  6939. }
  6940. else
  6941. {
  6942. tempIndex = gun_index;
  6943. }
  6944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6945. {
  6946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6947. {
  6948. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6949. }
  6950. } // END OF FOR CHAdeMO_QUANTITY
  6951. }
  6952. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6953. {
  6954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6955. {
  6956. tempIndex = ((gun_index==2) ? 1: 0);
  6957. }
  6958. else
  6959. {
  6960. tempIndex = gun_index;
  6961. }
  6962. for (int index = 0; index < CCS_QUANTITY; index++)
  6963. {
  6964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6965. {
  6966. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6967. }
  6968. } // END OF CCS_QUANTITY
  6969. }
  6970. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6971. {
  6972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6973. {
  6974. tempIndex = ((gun_index==2) ? 1: 0);
  6975. }
  6976. else
  6977. {
  6978. tempIndex = gun_index;
  6979. }
  6980. for (int index = 0; index < GB_QUANTITY; index++)
  6981. {
  6982. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6983. {
  6984. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6985. }
  6986. } // END OF GB_QUANTITY
  6987. }
  6988. else if(gunType[gun_index] == GUN_TYPE_DO)
  6989. {
  6990. tempIndex = gun_index;
  6991. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6992. {
  6993. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6994. {
  6995. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6996. }
  6997. }
  6998. }
  6999. else
  7000. {
  7001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7002. {
  7003. tempIndex = 2;
  7004. }
  7005. else
  7006. {
  7007. tempIndex = gun_index;
  7008. }
  7009. for (int index = 0; index < AC_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7012. {
  7013. uint16_t currentOffer;
  7014. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7015. {
  7016. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7017. }
  7018. else
  7019. {
  7020. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7021. }
  7022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7023. }
  7024. }
  7025. }
  7026. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7031. }
  7032. //***********************************************(12)Power.Offered******************************************************/
  7033. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7034. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7035. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7036. {
  7037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7038. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7039. {
  7040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7041. {
  7042. tempIndex = ((gun_index==2) ? 1: 0);
  7043. }
  7044. else
  7045. {
  7046. tempIndex = gun_index;
  7047. }
  7048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7049. {
  7050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7051. {
  7052. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7053. }
  7054. } // END OF FOR CHAdeMO_QUANTITY
  7055. }
  7056. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7057. {
  7058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7059. {
  7060. tempIndex = ((gun_index==2) ? 1: 0);
  7061. }
  7062. else
  7063. {
  7064. tempIndex = gun_index;
  7065. }
  7066. for (int index = 0; index < CCS_QUANTITY; index++)
  7067. {
  7068. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7069. {
  7070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7071. }
  7072. } // END OF CCS_QUANTITY
  7073. }
  7074. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7075. {
  7076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7077. {
  7078. tempIndex = ((gun_index==2) ? 1: 0);
  7079. }
  7080. else
  7081. {
  7082. tempIndex = gun_index;
  7083. }
  7084. for (int index = 0; index < GB_QUANTITY; index++)
  7085. {
  7086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7087. {
  7088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7089. }
  7090. } // END OF GB_QUANTITY
  7091. }
  7092. else if(gunType[gun_index] == GUN_TYPE_DO)
  7093. {
  7094. tempIndex = gun_index;
  7095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7096. {
  7097. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7098. {
  7099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7100. }
  7101. }
  7102. }
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7108. }
  7109. // Message create ====================================================================================================
  7110. if(TRUE)
  7111. {
  7112. json_object *MeterValueReq = json_object_new_object();
  7113. json_object *MeterValues = json_object_new_array();
  7114. json_object *sampledValues = json_object_new_array();
  7115. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7116. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7117. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7118. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7119. {
  7120. json_object *MeterValue = json_object_new_object();
  7121. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7122. {
  7123. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7124. {
  7125. json_object *sampledValue = json_object_new_object();
  7126. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7127. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7128. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7129. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7130. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7131. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7132. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7133. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7134. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7135. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7136. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7137. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7138. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7139. json_object_array_add(sampledValues, sampledValue);
  7140. }
  7141. }
  7142. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7143. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7144. json_object_array_add(MeterValues, MeterValue);
  7145. }
  7146. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7147. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7148. ,gun_index + 1
  7149. ,MESSAGE_TYPE_CALL
  7150. ,guid
  7151. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7152. json_object_put(MeterValueReq);
  7153. }
  7154. // Put request guid to hash map
  7155. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7156. 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*/)
  7157. {
  7158. result = PASS;
  7159. //DEBUG_INFO("MeterValues mapitem pass\n");
  7160. }
  7161. if((dataType != ReadingContext_Trigger) &&
  7162. (dataType != ReadingContext_Sample_Clock) &&
  7163. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7164. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7165. else
  7166. {
  7167. if(FirstHeartBeat)
  7168. LWS_Send(queuedata +2);
  7169. }
  7170. return result;
  7171. }
  7172. int sendLogStatusNotificationRequest(char *status)
  7173. {
  7174. mtrace();
  7175. int result = PASS;
  7176. char message[4096]={0};
  7177. char guid[37]={0};
  7178. char tempdata[128]={0};
  7179. json_object *LogStatusNotification = json_object_new_object();
  7180. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7181. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7182. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7183. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7184. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7185. random_uuid(guid);
  7186. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7187. json_object_put(LogStatusNotification);
  7188. LWS_Send(message);
  7189. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7190. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7191. {
  7192. result = PASS;
  7193. }
  7194. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7195. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7196. return result;
  7197. }
  7198. int sendSecurityEventNotificationRequest()
  7199. {
  7200. mtrace();
  7201. int result = PASS;
  7202. char message[4096]={0};
  7203. char guid[37]={0};
  7204. char tempdata[128]={0};
  7205. json_object *SecurityEventNotification = json_object_new_object();
  7206. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7207. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7208. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7209. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7210. random_uuid(guid);
  7211. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7212. json_object_put(SecurityEventNotification);
  7213. LWS_Send(message);
  7214. sprintf(tempdata, "SecurityEventNotification,0");
  7215. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7216. {
  7217. result = PASS;
  7218. }
  7219. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7220. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7221. return result;
  7222. }
  7223. int sendSignCertificateRequest()
  7224. {
  7225. mtrace();
  7226. int result = PASS;
  7227. char message[4096]={0};
  7228. char guid[37]={0};
  7229. char tempdata[128]={0};
  7230. json_object *SignCertificate = json_object_new_object();
  7231. DEBUG_INFO("sendSignCertificateRequest...\n");
  7232. // Read csr file content
  7233. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7234. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7235. char *line = NULL;
  7236. size_t len = 0;
  7237. while(getline(&line, &len, fp) != -1)
  7238. {
  7239. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7240. {
  7241. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7242. }
  7243. }
  7244. fclose(fp);
  7245. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7246. random_uuid(guid);
  7247. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7248. json_object_put(SignCertificate);
  7249. LWS_Send(message);
  7250. sprintf(tempdata, "SignCertificate,0");
  7251. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7252. {
  7253. result = PASS;
  7254. }
  7255. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7256. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7257. return result;
  7258. }
  7259. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7260. {
  7261. mtrace();
  7262. int result = PASS;
  7263. char message[110]={0};
  7264. char guid[37]={0};
  7265. char tempdata[65]={0};
  7266. json_object *FirmwareStatusNotification = json_object_new_object();
  7267. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7268. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7269. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7270. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7271. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7272. random_uuid(guid);
  7273. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7274. json_object_put(FirmwareStatusNotification);
  7275. LWS_Send(message);
  7276. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7277. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7278. {
  7279. result = PASS;
  7280. }
  7281. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7282. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7283. return result;
  7284. }
  7285. //==========================================
  7286. // send confirm routine
  7287. //==========================================
  7288. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7289. {
  7290. mtrace();
  7291. int result = FAIL;
  7292. char message[100]={0};
  7293. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7295. LWS_Send(message);
  7296. result = TRUE;
  7297. return result;
  7298. }
  7299. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. char message[100]={0};
  7304. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7306. LWS_Send(message);
  7307. result = TRUE;
  7308. return result;
  7309. }
  7310. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7311. {
  7312. mtrace();
  7313. int result = FAIL;
  7314. char message[100]={0};
  7315. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7316. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7317. LWS_Send(message);
  7318. result = TRUE;
  7319. return result;
  7320. }
  7321. int sendClearCacheConfirmation(char *uuid,char *payload)
  7322. {
  7323. mtrace();
  7324. int result = FAIL;
  7325. char message[500]={0};
  7326. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7327. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7328. LWS_Send(message);
  7329. return result;
  7330. }
  7331. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7332. {
  7333. mtrace();
  7334. int result = FAIL;
  7335. char message[500]={0};
  7336. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7337. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7338. LWS_Send(message);
  7339. return result;
  7340. }
  7341. int sendDataTransferConfirmation(char *uuid,char *payload)
  7342. {
  7343. mtrace();
  7344. char statusStr[20]={0};
  7345. char dataStr[10]={0};
  7346. char sstr[20]={0};
  7347. int c = 0;
  7348. char *loc;
  7349. int result = FAIL;
  7350. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7351. /**********************status**************************/
  7352. loc = strstr(payload, "status");
  7353. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7354. c = 0;
  7355. while (loc[3+strlen("status")+c] != '\"')
  7356. {
  7357. sstr[c] = loc[3+strlen("status")+c];
  7358. c++;
  7359. }
  7360. sstr[c] = '\0';
  7361. strcpy(statusStr, sstr);
  7362. /**********************data**************************/
  7363. loc = strstr(payload, "data");
  7364. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7365. c = 0;
  7366. while (loc[3+strlen("data")+c] != '\"')
  7367. {
  7368. sstr[c] = loc[3+strlen("data")+c];
  7369. c++;
  7370. }
  7371. sstr[c] = '\0';
  7372. strcpy(dataStr, sstr);
  7373. return result;
  7374. }
  7375. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7376. {
  7377. mtrace();
  7378. int result = FAIL;
  7379. char message[1000]={0};
  7380. int CompositeScheduleIndex = 0;
  7381. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7382. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7383. if(nPeriod == 0)
  7384. {
  7385. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7386. {
  7387. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7388. ,MESSAGE_TYPE_CALLRESULT
  7389. ,uuid
  7390. ,payload
  7391. ,connectorIdInt);
  7392. }
  7393. else
  7394. {
  7395. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7396. ,MESSAGE_TYPE_CALLRESULT
  7397. ,uuid
  7398. ,payload
  7399. ,connectorIdInt
  7400. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7401. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7402. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7403. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7404. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7405. }
  7406. }
  7407. else
  7408. {
  7409. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7410. ,MESSAGE_TYPE_CALLRESULT
  7411. ,uuid
  7412. ,payload
  7413. ,connectorIdInt
  7414. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7415. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7416. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7417. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7418. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7419. {
  7420. if (idx_sample == 0)
  7421. {
  7422. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7423. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7424. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7425. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7426. }
  7427. else
  7428. {
  7429. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7430. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7431. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7432. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7433. }
  7434. }
  7435. sprintf(message + strlen(message), "]}}]");
  7436. }
  7437. LWS_Send(message);
  7438. result = TRUE;
  7439. return result;
  7440. }
  7441. int sendGetConfigurationConfirmation(char *uuid)
  7442. {
  7443. mtrace();
  7444. int result = FAIL;
  7445. int MaxKeySupported = 0;
  7446. int sentConfigurationNumber= 0;
  7447. int sentunConfigurationNumber= 0;
  7448. char message[1024*10]={0};
  7449. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7450. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7451. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7452. ,MESSAGE_TYPE_CALLRESULT
  7453. ,uuid );
  7454. //configuration key
  7455. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7456. {
  7457. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7458. {
  7459. if (sentConfigurationNumber == 0)
  7460. {
  7461. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7462. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7463. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7464. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7465. }
  7466. else
  7467. {
  7468. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7469. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7470. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7471. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7472. }
  7473. sentConfigurationNumber = sentConfigurationNumber + 1;
  7474. }
  7475. }
  7476. sprintf(message + strlen(message), "]");
  7477. if(UnknownKeynum != 0)
  7478. {
  7479. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7480. //unkown key
  7481. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7482. {
  7483. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7484. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7485. if(sentunConfigurationNumber == 0)
  7486. {
  7487. sprintf(message + strlen(message), "\"%s\""
  7488. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7489. }
  7490. else
  7491. {
  7492. sprintf(message + strlen(message), ",\"%s\""
  7493. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7494. }
  7495. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7496. }
  7497. sprintf(message + strlen(message), "]");
  7498. }
  7499. sprintf(message + strlen(message), "}]");
  7500. LWS_Send(message);
  7501. return result;
  7502. }
  7503. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7504. {
  7505. mtrace();
  7506. int result = FAIL;
  7507. char message[400]={0};
  7508. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7509. if(strcmp(payload,"")==0)
  7510. {
  7511. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7512. }
  7513. else
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7516. }
  7517. LWS_Send(message);
  7518. result = TRUE;
  7519. return result;
  7520. }
  7521. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7522. {
  7523. mtrace();
  7524. int result = FAIL;
  7525. char message[80]={0};
  7526. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7527. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7528. LWS_Send(message);
  7529. result = TRUE;
  7530. return result;
  7531. }
  7532. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7533. {
  7534. mtrace();
  7535. int result = FAIL;
  7536. char message[80]={0};
  7537. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7538. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7539. LWS_Send(message);
  7540. result = TRUE;
  7541. return result;
  7542. }
  7543. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7544. {
  7545. mtrace();
  7546. int result = FAIL;
  7547. char message[80]={0};
  7548. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7549. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7550. LWS_Send(message);
  7551. result = TRUE;
  7552. return result;
  7553. }
  7554. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7555. {
  7556. mtrace();
  7557. int result = FAIL;
  7558. char message[80]={0};
  7559. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7560. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7561. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7562. LWS_Send(message);
  7563. result = TRUE;
  7564. return result;
  7565. }
  7566. int sendResetConfirmation(char *uuid,char *payload)
  7567. {
  7568. mtrace();
  7569. int result = FAIL;
  7570. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7571. char message[80]={0};
  7572. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7573. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7574. LWS_Send(message);
  7575. result = TRUE;
  7576. return result;
  7577. }
  7578. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7579. {
  7580. mtrace();
  7581. int result = FAIL;
  7582. char message[500]={0};
  7583. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7584. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7585. LWS_Send(message);
  7586. result = TRUE;
  7587. return result;
  7588. }
  7589. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7590. {
  7591. mtrace();
  7592. int result = FAIL;
  7593. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7594. char message[80]={0};
  7595. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7596. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7597. LWS_Send(message);
  7598. result = TRUE;
  7599. return result;
  7600. }
  7601. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7602. {
  7603. mtrace();
  7604. int result = FAIL;
  7605. char message[80]={0};
  7606. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7607. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7608. LWS_Send(message);
  7609. result = TRUE;
  7610. return result;
  7611. }
  7612. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7613. {
  7614. mtrace();
  7615. int result = FAIL;
  7616. char message[80]={0};
  7617. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7618. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7619. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7620. LWS_Send(message);
  7621. result = TRUE;
  7622. return result;
  7623. }
  7624. int sendUpdateFirmwareConfirmation(char *uuid)
  7625. {
  7626. mtrace();
  7627. int result = FAIL;
  7628. char message[60]={0};
  7629. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7630. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7631. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7632. LWS_Send(message);
  7633. result = TRUE;
  7634. return result;
  7635. }
  7636. int sendCertificateSignedConfirmation(char *uuid)
  7637. {
  7638. mtrace();
  7639. int result = PASS;
  7640. char message[4096]={0};
  7641. json_object *CertificateSigned = json_object_new_object();
  7642. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7643. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7644. sprintf(message,"[%d,\"%s\",%s]"
  7645. ,MESSAGE_TYPE_CALLRESULT
  7646. ,uuid
  7647. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7648. json_object_put(CertificateSigned);
  7649. LWS_Send(message);
  7650. return result;
  7651. }
  7652. int sendDeleteCertificateConfirmation(char *uuid)
  7653. {
  7654. mtrace();
  7655. int result = PASS;
  7656. char message[4096]={0};
  7657. json_object *DeleteCertificate = json_object_new_object();
  7658. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7659. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7660. sprintf(message,"[%d,\"%s\",%s]"
  7661. ,MESSAGE_TYPE_CALLRESULT
  7662. ,uuid
  7663. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7664. json_object_put(DeleteCertificate);
  7665. LWS_Send(message);
  7666. return result;
  7667. }
  7668. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7669. {
  7670. mtrace();
  7671. int result = PASS;
  7672. char message[4096]={0};
  7673. json_object *ExtendedTriggerMessage = json_object_new_object();
  7674. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7675. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7676. sprintf(message,"[%d,\"%s\",%s]"
  7677. ,MESSAGE_TYPE_CALLRESULT
  7678. ,uuid
  7679. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7680. json_object_put(ExtendedTriggerMessage);
  7681. LWS_Send(message);
  7682. return result;
  7683. }
  7684. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7685. {
  7686. mtrace();
  7687. int result = PASS;
  7688. char message[4096]={0};
  7689. json_object *GetInstalledCertificateIds = json_object_new_object();
  7690. json_object *certificateHashDataDatas = json_object_new_array();
  7691. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7692. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7693. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7694. {
  7695. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7696. {
  7697. json_object *certificateHashData = json_object_new_object();
  7698. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7699. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7700. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7701. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7702. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7703. }
  7704. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7705. }
  7706. else
  7707. {
  7708. json_object_put(certificateHashDataDatas);
  7709. }
  7710. sprintf(message,"[%d,\"%s\",%s]"
  7711. ,MESSAGE_TYPE_CALLRESULT
  7712. ,uuid
  7713. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7714. json_object_put(GetInstalledCertificateIds);
  7715. LWS_Send(message);
  7716. return result;
  7717. }
  7718. int sendGetLogConfirmation(char *uuid)
  7719. {
  7720. mtrace();
  7721. int result = PASS;
  7722. char message[4096]={0};
  7723. json_object *GetLog = json_object_new_object();
  7724. DEBUG_INFO("sendGetLogConfirmation...\n");
  7725. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7726. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7727. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7728. sprintf(message,"[%d,\"%s\",%s]"
  7729. ,MESSAGE_TYPE_CALLRESULT
  7730. ,uuid
  7731. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7732. json_object_put(GetLog);
  7733. LWS_Send(message);
  7734. return result;
  7735. }
  7736. int sendInstallCertificateConfirmation(char *uuid)
  7737. {
  7738. mtrace();
  7739. int result = PASS;
  7740. char message[4096]={0};
  7741. json_object *InstallCertificate = json_object_new_object();
  7742. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7743. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7744. sprintf(message,"[%d,\"%s\",%s]"
  7745. ,MESSAGE_TYPE_CALLRESULT
  7746. ,uuid
  7747. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7748. json_object_put(InstallCertificate);
  7749. LWS_Send(message);
  7750. return result;
  7751. }
  7752. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7753. {
  7754. mtrace();
  7755. int result = PASS;
  7756. char message[4096]={0};
  7757. json_object *SignedUpdateFirmware = json_object_new_object();
  7758. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7759. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7760. sprintf(message,"[%d,\"%s\",%s]"
  7761. ,MESSAGE_TYPE_CALLRESULT
  7762. ,uuid
  7763. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7764. json_object_put(SignedUpdateFirmware);
  7765. LWS_Send(message);
  7766. return result;
  7767. }
  7768. int sendUnknownConfirmation(char *uuid)
  7769. {
  7770. mtrace();
  7771. int result = PASS;
  7772. char message[256]={0};
  7773. DEBUG_INFO("sendUnknownConfirmation...\n");
  7774. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7775. LWS_Send(message);
  7776. return result;
  7777. }
  7778. //==========================================
  7779. // Handle server request routine Start
  7780. //==========================================
  7781. int handleCancelReservationRequest(char *uuid, char *payload)
  7782. {
  7783. mtrace();
  7784. int result = FAIL;
  7785. int gunNO = 0;
  7786. int reservationIdInt = -1;
  7787. char comfirmstr[20];
  7788. DEBUG_INFO("handleCancelReservationRequest...\n");
  7789. json_object *CancelReservation;
  7790. CancelReservation = json_tokener_parse(payload);
  7791. if(!is_error(CancelReservation))
  7792. {
  7793. // Required data
  7794. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7795. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7796. }
  7797. json_object_put(CancelReservation);
  7798. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7799. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7800. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7801. if(reservationIdInt != -1)
  7802. {
  7803. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7804. //check Transaction active
  7805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7807. {
  7808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7809. {
  7810. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7811. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7812. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7813. {
  7814. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7815. }
  7816. else
  7817. {
  7818. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7819. }
  7820. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7821. goto end;
  7822. }
  7823. }
  7824. for (int index = 0; index < CCS_QUANTITY; index++)
  7825. {
  7826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7827. {
  7828. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7829. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7830. if(gunType[2] == GUN_TYPE_CCS)
  7831. {
  7832. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7833. }
  7834. else
  7835. {
  7836. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7837. }
  7838. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7839. goto end;
  7840. }
  7841. }
  7842. for (int index = 0; index < GB_QUANTITY; index++)
  7843. {
  7844. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7845. {
  7846. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7847. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7848. if(gunType[2] == GUN_TYPE_GBT)
  7849. {
  7850. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7851. }
  7852. else
  7853. {
  7854. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7855. }
  7856. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7857. goto end;
  7858. }
  7859. }
  7860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7861. {
  7862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7863. {
  7864. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7865. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7866. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7867. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7868. goto end;
  7869. }
  7870. }
  7871. for (int index = 0; index < AC_QUANTITY; index++)
  7872. {
  7873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7874. {
  7875. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7876. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7878. {
  7879. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7880. }
  7881. else
  7882. {
  7883. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7884. }
  7885. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7886. goto end;
  7887. }
  7888. }
  7889. }
  7890. //The reservationId does NOT match the reservationId
  7891. sendCancelReservationConfirmation(uuid, comfirmstr);
  7892. end:
  7893. // Fill in ocpp packet uuid
  7894. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7895. return result;
  7896. }
  7897. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7898. {
  7899. mtrace();
  7900. int result = FAIL;
  7901. int gunIndex = -1;
  7902. char typeStr[16]={0};
  7903. char comfirmstr[20];
  7904. int specificId = FALSE;
  7905. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7906. json_object *ChangeAvailability;
  7907. ChangeAvailability = json_tokener_parse(payload);
  7908. if(!is_error(ChangeAvailability))
  7909. {
  7910. // Required data
  7911. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7912. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7913. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7914. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7915. }
  7916. json_object_put(ChangeAvailability);
  7917. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7918. {
  7919. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7920. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7921. }
  7922. else if(gunIndex == 0)
  7923. {
  7924. for(int i=0; i < gunTotalNumber; i++)
  7925. {
  7926. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7927. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7928. }
  7929. }
  7930. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7932. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7933. {
  7934. specificId = TRUE;
  7935. }
  7936. if(specificId == FALSE)
  7937. goto end;
  7938. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7939. {
  7940. //----------------------gunIndex is 0 ------------------------------------------------//
  7941. if(gunIndex == 0)
  7942. {
  7943. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7944. {
  7945. for(int i=0; i < gunTotalNumber; i++)
  7946. {
  7947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7948. {
  7949. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7950. {
  7951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7952. {
  7953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7954. goto end;
  7955. }
  7956. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7957. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7958. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7959. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7960. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7961. {
  7962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7963. goto end;
  7964. }
  7965. }
  7966. }//END FOR CHAdeMO_QUANTITY
  7967. for (int index = 0; index < CCS_QUANTITY; index++)
  7968. {
  7969. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7970. {
  7971. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7972. {
  7973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7974. goto end;
  7975. }
  7976. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7977. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7978. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7981. {
  7982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7983. goto end;
  7984. }
  7985. }
  7986. }//END FOR CCS_QUANTITY
  7987. for (int index = 0; index < GB_QUANTITY; index++)
  7988. {
  7989. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7990. {
  7991. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7992. {
  7993. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7994. goto end;
  7995. }
  7996. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7997. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7998. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7999. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8000. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8001. {
  8002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8003. goto end;
  8004. }
  8005. }
  8006. }// END FOR GB_QUANTITY
  8007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8008. {
  8009. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8010. {
  8011. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8012. {
  8013. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8014. goto end;
  8015. }
  8016. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8017. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8018. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8019. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8020. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8021. {
  8022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8023. goto end;
  8024. }
  8025. }
  8026. }// END FOR GENERAL_GUN_QUANTITY
  8027. for (int index = 0; index < AC_QUANTITY; index++)
  8028. {
  8029. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8030. {
  8031. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8032. {
  8033. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8034. goto end;
  8035. }
  8036. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8037. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8038. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8039. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8040. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8041. {
  8042. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8043. goto end;
  8044. }
  8045. }
  8046. }//END FOR AC_QUANTITY
  8047. }// END FOR gunTotalNumber
  8048. }
  8049. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8050. {
  8051. for(int i=0; i < gunTotalNumber; i++)
  8052. {
  8053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8054. {
  8055. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8056. goto end;
  8057. }
  8058. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8059. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8060. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8061. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8062. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8063. {
  8064. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8065. goto end;
  8066. }
  8067. }
  8068. }
  8069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8070. goto end;
  8071. }
  8072. //----------------------gunIndex is not 0 ------------------------------------------------//
  8073. //check Transaction active
  8074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8075. {
  8076. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8077. {
  8078. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8079. {
  8080. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8081. goto end;
  8082. }
  8083. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8088. {
  8089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8090. goto end;
  8091. }
  8092. else
  8093. {
  8094. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8095. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8096. goto end;
  8097. }
  8098. }
  8099. }//END FOR CHAdeMO_QUANTITY
  8100. for (int index = 0; index < CCS_QUANTITY; index++)
  8101. {
  8102. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8103. {
  8104. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8105. {
  8106. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8107. goto end;
  8108. }
  8109. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8110. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8114. {
  8115. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8116. goto end;
  8117. }
  8118. else
  8119. {
  8120. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8122. goto end;
  8123. }
  8124. }
  8125. }//END FOR CCS_QUANTITY
  8126. for (int index = 0; index < GB_QUANTITY; index++)
  8127. {
  8128. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8129. {
  8130. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8131. {
  8132. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8133. goto end;
  8134. }
  8135. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8140. {
  8141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8142. goto end;
  8143. }
  8144. else
  8145. {
  8146. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8147. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8148. goto end;
  8149. }
  8150. }
  8151. }// END FOR GB_QUANTITY
  8152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8153. {
  8154. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8155. {
  8156. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8157. {
  8158. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8159. goto end;
  8160. }
  8161. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8163. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8166. {
  8167. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8168. goto end;
  8169. }
  8170. else
  8171. {
  8172. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8173. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8174. goto end;
  8175. }
  8176. }
  8177. }// END FOR GENERAL_GUN_QUANTITY
  8178. for (int index = 0; index < AC_QUANTITY; index++)
  8179. {
  8180. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8181. {
  8182. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8183. {
  8184. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8185. goto end;
  8186. }
  8187. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8192. {
  8193. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8194. goto end;
  8195. }
  8196. else
  8197. {
  8198. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8200. goto end;
  8201. }
  8202. }
  8203. }//END FOR AC_QUANTITY
  8204. }//END FOR AvailabilityTypeStr[Inoperative]
  8205. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8206. {
  8207. //----------------------gunIndex is 0 ------------------------------------------------//
  8208. if(gunIndex == 0)
  8209. {
  8210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8211. {
  8212. for(int i=0; i < gunTotalNumber; i++)
  8213. {
  8214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8215. {
  8216. 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
  8217. {
  8218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8219. goto end;
  8220. }
  8221. }//END FOR CHAdeMO_QUANTITY
  8222. for (int index = 0; index < CCS_QUANTITY; index++)
  8223. {
  8224. 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
  8225. {
  8226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8227. goto end;
  8228. }
  8229. }//END FOR CCS_QUANTITY
  8230. for (int index = 0; index < GB_QUANTITY; index++)
  8231. {
  8232. 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
  8233. {
  8234. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8236. goto end;
  8237. }
  8238. }// END FOR GB_QUANTITY
  8239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8240. {
  8241. 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
  8242. {
  8243. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8245. goto end;
  8246. }
  8247. }// END FOR GENERAL_GUN_QUANTITY
  8248. for (int index = 0; index < AC_QUANTITY; index++)
  8249. {
  8250. 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
  8251. {
  8252. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8253. goto end;
  8254. }
  8255. }//END FOR CHAdeMO_QUANTITY
  8256. }// END FOR gunTotalNumber
  8257. }
  8258. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8259. {
  8260. for(int i=0; i < gunTotalNumber; i++)
  8261. {
  8262. for (int index = 0; index < AC_QUANTITY; index++)
  8263. {
  8264. 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
  8265. {
  8266. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8267. goto end;
  8268. }
  8269. }//END FOR CHAdeMO_QUANTITY
  8270. } // END FOR gunTotalNumber
  8271. }
  8272. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8273. goto end;
  8274. }
  8275. //----------------------gunIndex is not 0 ------------------------------------------------//
  8276. //check Transaction active
  8277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8278. {
  8279. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8280. {
  8281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8282. goto end;
  8283. }
  8284. }//END FOR CHAdeMO_QUANTITY
  8285. for (int index = 0; index < CCS_QUANTITY; index++)
  8286. {
  8287. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8288. {
  8289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8290. goto end;
  8291. }
  8292. }//END FOR CCS_QUANTITY
  8293. for (int index = 0; index < GB_QUANTITY; index++)
  8294. {
  8295. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8296. {
  8297. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8298. goto end;
  8299. }
  8300. }// END FOR GB_QUANTITY
  8301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8302. {
  8303. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8304. {
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8306. goto end;
  8307. }
  8308. }// END FOR GENERAL_GUN_QUANTITY
  8309. for (int index = 0; index < AC_QUANTITY; index++)
  8310. {
  8311. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8312. {
  8313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8314. goto end;
  8315. }
  8316. }//END FOR AC_QUANTITY
  8317. }//END FOR AvailabilityTypeStr[Operative]
  8318. end:
  8319. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8320. {
  8321. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8322. }
  8323. else
  8324. {
  8325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8326. }
  8327. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8328. {
  8329. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8330. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8331. }
  8332. else if(gunIndex == 0)
  8333. {
  8334. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8335. {
  8336. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8337. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8338. }
  8339. }
  8340. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8342. return result;
  8343. }
  8344. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8345. {
  8346. mtrace();
  8347. int valueInvalid = NO;
  8348. int result = FAIL;
  8349. char keystr[40]={0};
  8350. char valuestr[501]={0}; //value should be limited in 500 bytes
  8351. char comfirmstr[20]={0};
  8352. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8353. json_object *ChangeConfiguration;
  8354. ChangeConfiguration = json_tokener_parse(payload);
  8355. if(!is_error(ChangeConfiguration))
  8356. {
  8357. // Required data
  8358. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8359. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8360. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8361. {
  8362. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8363. }
  8364. else
  8365. {
  8366. valueInvalid = YES;
  8367. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8368. }
  8369. }
  8370. json_object_put(ChangeConfiguration);
  8371. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8372. {
  8373. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8374. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8375. }
  8376. else
  8377. {
  8378. int status = setKeyValue(keystr, valuestr);
  8379. switch(status)
  8380. {
  8381. case ConfigurationStatus_Accepted:
  8382. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8383. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8384. StoreConfigurationTable();
  8385. break;
  8386. case RebootRequired:
  8387. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8388. StoreConfigurationTable();
  8389. break;
  8390. case NotSupported:
  8391. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8392. break;
  8393. case ConfigurationStatus_Rejected:
  8394. default:
  8395. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8396. break;
  8397. }
  8398. }
  8399. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8400. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8401. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8402. {
  8403. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8404. SetOcppConnStatus(FALSE);
  8405. }
  8406. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8407. {
  8408. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8409. }
  8410. return result;
  8411. }
  8412. int handleClearCacheRequest(char *uuid, char *payload)
  8413. {
  8414. mtrace();
  8415. int result = FAIL;
  8416. char comfirmstr[20];
  8417. char rmFileCmd[100]={0};
  8418. struct stat stats;
  8419. DEBUG_INFO("handleClearCacheRequest...\n");
  8420. stat("/Storage/OCPP", &stats);
  8421. // Check for directory existence
  8422. if (S_ISDIR(stats.st_mode) == 1)
  8423. {}
  8424. else
  8425. {
  8426. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8427. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8428. system(rmFileCmd);
  8429. }
  8430. if(OCPP_cleanLocalCache())
  8431. {
  8432. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8433. }
  8434. else
  8435. {
  8436. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8437. }
  8438. sendClearCacheConfirmation(uuid, comfirmstr);
  8439. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8440. return result;
  8441. }
  8442. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8443. {
  8444. mtrace();
  8445. int result = FAIL;
  8446. int resultRename;
  8447. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8448. char chargingProfilePurposeStr[26]={0};
  8449. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8450. char tempchargingProfilePurposeStr[26]={0};
  8451. char str[100]={0};
  8452. char fname[200]={0};
  8453. char comfirmstr[20]={0};
  8454. char word[1600]={0};
  8455. int clearflag = FALSE;
  8456. int chargingProfileIdIsNULL = FALSE;
  8457. int connectorIsNULL = FALSE;
  8458. int chargingProfilePurposeIsNULL = FALSE;
  8459. int stackLevelIsNULL = FALSE;
  8460. //int GotoEnd = FALSE;
  8461. FILE *fptr1, *fptr2;
  8462. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8463. int n_chargingProfile=0;
  8464. int isEmptyFile = FALSE;
  8465. char sLineWord[1600]={0};
  8466. char chargingProfiles[10][100]={0};
  8467. int ChargeProfileCount = 0;
  8468. int ch;
  8469. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8470. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8471. json_object *ClearChargingProfile;
  8472. ClearChargingProfile = json_tokener_parse(payload);
  8473. if(!is_error(ClearChargingProfile))
  8474. {
  8475. // Optional data
  8476. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8477. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8478. else
  8479. chargingProfileIdIsNULL = TRUE;
  8480. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8481. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8482. else
  8483. connectorIsNULL = TRUE;
  8484. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8485. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8486. else
  8487. chargingProfilePurposeIsNULL = TRUE;
  8488. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8489. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8490. else
  8491. stackLevelIsNULL = TRUE;
  8492. }
  8493. json_object_put(ClearChargingProfile);
  8494. if(connectorIsNULL == FALSE)
  8495. {
  8496. switch(connectorIdInt)
  8497. {
  8498. case 0:
  8499. if(chargingProfilePurposeIsNULL == TRUE)
  8500. {
  8501. int l = 0;
  8502. strcpy(fname, ChargePointMaxProfile_JSON);
  8503. if((access(fname,F_OK))!=-1)
  8504. {
  8505. strcpy(chargingProfiles[l], fname);
  8506. l = l + 1;
  8507. }
  8508. strcpy(fname, TxDefaultProfile_0_JSON);
  8509. if((access(fname,F_OK))!=-1)
  8510. {
  8511. strcpy(chargingProfiles[l], fname);
  8512. l = l + 1;
  8513. }
  8514. ChargeProfileCount = l;
  8515. }
  8516. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8517. {
  8518. strcpy(fname, ChargePointMaxProfile_JSON);
  8519. if((access(fname,F_OK))!=-1)
  8520. {
  8521. strcpy(chargingProfiles[0], fname);
  8522. ChargeProfileCount = 1;
  8523. }
  8524. }
  8525. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8526. {
  8527. strcpy(fname, TxDefaultProfile_0_JSON);
  8528. if((access(fname,F_OK))!=-1)
  8529. {
  8530. strcpy(chargingProfiles[0], fname);
  8531. ChargeProfileCount = 1;
  8532. }
  8533. }
  8534. break;
  8535. default:
  8536. if(chargingProfilePurposeIsNULL == TRUE)
  8537. {
  8538. int m = 0;
  8539. memset(fname, 0, ARRAY_SIZE(fname));
  8540. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8541. if((access(fname,F_OK))!=-1)
  8542. {
  8543. strcpy(chargingProfiles[m], fname);
  8544. m = m + 1;
  8545. }
  8546. memset(fname, 0, ARRAY_SIZE(fname));
  8547. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8548. if((access(fname,F_OK))!=-1)
  8549. {
  8550. strcpy(chargingProfiles[m], fname);
  8551. m = m + 1;
  8552. }
  8553. ChargeProfileCount = m;
  8554. }
  8555. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8556. {
  8557. //strcpy(fname, TxDefaultProfile_1_JSON);
  8558. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8559. if((access(fname,F_OK))!=-1)
  8560. {
  8561. strcpy(chargingProfiles[0], fname);
  8562. ChargeProfileCount = 1;
  8563. }
  8564. }
  8565. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8566. {
  8567. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8568. if((access(fname,F_OK))!=-1)
  8569. {
  8570. strcpy(chargingProfiles[0], fname);
  8571. ChargeProfileCount = 1;
  8572. }
  8573. //strcpy(fname, TxProfile_1_JSON);
  8574. }
  8575. //strcpy(fname, ChargePointMaxProfile_JSON );
  8576. break;
  8577. }
  8578. }
  8579. else // Check all Charging Profiles
  8580. {
  8581. int i = 0;
  8582. char fnametemp[200]={0};
  8583. ChargeProfileCount = 0;
  8584. //Check ChargePointMaxProfile.json exit
  8585. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8586. {
  8587. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8588. i = i + 1;
  8589. }
  8590. //Check TxDefaultProfile_0.json exit
  8591. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8592. {
  8593. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8594. i = i + 1;
  8595. }
  8596. //Check TxDefaultProfile_%d.json
  8597. for(int j=1; j <= gunTotalNumber; j++)
  8598. {
  8599. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8600. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8601. if((access(fnametemp,F_OK))!=-1)
  8602. {
  8603. strcpy(chargingProfiles[i], fnametemp);
  8604. i = i + 1;
  8605. }
  8606. }
  8607. //Check TxProfile_%d.json
  8608. for(int j=1; j <= gunTotalNumber; j++)
  8609. {
  8610. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8611. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8612. if((access(fnametemp,F_OK))!=-1)
  8613. {
  8614. strcpy(chargingProfiles[i], fnametemp);
  8615. i = i + 1;
  8616. }
  8617. }
  8618. ChargeProfileCount = i;
  8619. }// End connectorIsNULL is TRUE
  8620. if(ChargeProfileCount == 0)
  8621. {
  8622. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8623. goto end;
  8624. }
  8625. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8626. {
  8627. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8628. goto end;
  8629. }
  8630. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8631. {
  8632. memset(str, 0, ARRAY_SIZE(str));
  8633. // clear temp file
  8634. sprintf(str,"rm -f %s",temp);
  8635. system(str);
  8636. for(int k=0; k < ChargeProfileCount; k++)
  8637. {
  8638. memset(str, 0, ARRAY_SIZE(str));
  8639. //clear file in C
  8640. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8641. system(str);
  8642. }
  8643. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8644. goto end;
  8645. }
  8646. else if(connectorIsNULL == TRUE)
  8647. {
  8648. for(int k=0; k < ChargeProfileCount; k++)
  8649. {
  8650. fptr1 = fopen(chargingProfiles[k], "r");
  8651. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8652. //Check Charging Profile Count
  8653. while(fscanf(fptr1, "%s", word) != EOF)
  8654. {
  8655. //DEBUG_INFO("word=%s\n",word);
  8656. if(strstr(word, "chargingProfileId")!= NULL)
  8657. {
  8658. //DEBUG_INFO("test chargingProfileId \n");
  8659. n_chargingProfile = n_chargingProfile + 1;
  8660. //DEBUG_INFO("chargingProfileId Found\n");
  8661. }
  8662. }
  8663. rewind(fptr1);
  8664. //search Charging Profile Element
  8665. //int i= 0;
  8666. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8667. {
  8668. json_object *tmpProfilee;
  8669. tmpProfilee = json_tokener_parse(sLineWord);
  8670. if(!is_error(tmpProfilee))
  8671. {
  8672. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8673. {
  8674. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8675. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8676. }
  8677. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8678. {
  8679. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8680. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8681. }
  8682. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8683. {
  8684. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8685. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8686. }
  8687. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8688. {
  8689. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8690. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8691. }
  8692. }
  8693. json_object_put(tmpProfilee);
  8694. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8695. {
  8696. //------- not write to fptr2-------//
  8697. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8698. //clearflag = TRUE;
  8699. }
  8700. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8701. {
  8702. //------- not write to fptr2-------//
  8703. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8704. }
  8705. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8706. {
  8707. //------- not write to fptr2-------//
  8708. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8709. }
  8710. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8711. {
  8712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8713. }
  8714. else
  8715. {
  8716. fprintf(fptr2, sLineWord);//writing data into file
  8717. }
  8718. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8719. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8720. if(clearflag == TRUE)
  8721. {
  8722. fclose(fptr1);
  8723. fclose(fptr2);
  8724. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8725. system(str);
  8726. // clear temp file
  8727. sprintf(str,"rm -f %s",temp);
  8728. system(str);
  8729. }
  8730. else
  8731. {
  8732. fclose(fptr1);
  8733. fclose(fptr2);
  8734. memset(str, 0, ARRAY_SIZE(str));
  8735. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8736. system(str);
  8737. resultRename = rename(temp, chargingProfiles[k]);
  8738. if(resultRename == 0)
  8739. {
  8740. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8741. }
  8742. else
  8743. {
  8744. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8745. }
  8746. if(comfirmstr[0]== 0)
  8747. {
  8748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8749. }
  8750. //Check chargingProfile is empty file
  8751. /*------ Read the file ----------------*/
  8752. fptr1=fopen(chargingProfiles[k],"r");
  8753. ch=fgetc(fptr1);
  8754. rewind(fptr1);
  8755. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8756. if(ch!=EOF)
  8757. {
  8758. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8759. {
  8760. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8761. if(sLineWord[0]=='\0')
  8762. {
  8763. isEmptyFile = TRUE;
  8764. break;
  8765. }
  8766. else
  8767. {
  8768. isEmptyFile = FALSE;
  8769. break;
  8770. }
  8771. }
  8772. }
  8773. else
  8774. isEmptyFile = TRUE;
  8775. fclose(fptr1);
  8776. if(isEmptyFile == TRUE)
  8777. {
  8778. memset(str, 0, ARRAY_SIZE(str));
  8779. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8780. system(str);
  8781. }
  8782. }
  8783. }// End of while(int k=0; k < ChargePointCount; k++)
  8784. }
  8785. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8786. {
  8787. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8788. for(int k=0; k < ChargeProfileCount; k++)
  8789. {
  8790. fptr1 = fopen(chargingProfiles[k], "r");
  8791. fptr2 = fopen(temp, "w+");
  8792. //Check Charging Profile Count
  8793. while(fscanf(fptr1, "%s", word) != EOF)
  8794. {
  8795. //DEBUG_INFO("word=%s\n",word);
  8796. if(strstr(word, "chargingProfileId")!= NULL)
  8797. {
  8798. n_chargingProfile = n_chargingProfile + 1;
  8799. }
  8800. }
  8801. rewind(fptr1);
  8802. //search Charging Profile Element
  8803. //int i= 0;
  8804. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8805. {
  8806. json_object *tmpProfilee;
  8807. tmpProfilee = json_tokener_parse(sLineWord);
  8808. if(!is_error(tmpProfilee))
  8809. {
  8810. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8811. {
  8812. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8813. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8814. }
  8815. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8816. {
  8817. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8818. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8819. }
  8820. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8821. {
  8822. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8823. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8824. }
  8825. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8826. {
  8827. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8828. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8829. }
  8830. }
  8831. json_object_put(tmpProfilee);
  8832. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8833. {
  8834. //------- not write to fptr2-------//
  8835. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8836. //clearflag = TRUE;
  8837. }
  8838. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8839. {
  8840. //------- not write to fptr2-------//
  8841. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8842. }
  8843. else if(stackLevelIsNULL == TRUE)
  8844. {
  8845. //Clear Whole File
  8846. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8847. clearflag = TRUE;
  8848. break;
  8849. }
  8850. else
  8851. {
  8852. fprintf(fptr2, sLineWord);//writing data into file
  8853. }
  8854. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8855. }
  8856. if(clearflag == TRUE)
  8857. {
  8858. fclose(fptr1);
  8859. fclose(fptr2);
  8860. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8861. system(str);
  8862. // clear temp file
  8863. sprintf(str,"rm -f %s",temp);
  8864. system(str);
  8865. }
  8866. else
  8867. {
  8868. fclose(fptr1);
  8869. fclose(fptr2);
  8870. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8871. system(str);
  8872. resultRename = rename(temp, chargingProfiles[k]);
  8873. if(resultRename == 0)
  8874. {
  8875. DEBUG_INFO("File ChargingProfile renamed successfully");
  8876. }
  8877. else
  8878. {
  8879. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8880. }
  8881. if(comfirmstr[0]== 0)
  8882. {
  8883. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8884. }
  8885. //Check chargingProfile is empty file
  8886. /*------ Read the file ----------------*/
  8887. fptr1=fopen(chargingProfiles[k],"r");
  8888. ch=fgetc(fptr1);
  8889. rewind(fptr1);
  8890. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8891. if(ch!=EOF)
  8892. {
  8893. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8894. {
  8895. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8896. if(sLineWord[0]=='\0')
  8897. {
  8898. isEmptyFile = TRUE;
  8899. break;
  8900. }
  8901. else
  8902. {
  8903. isEmptyFile = FALSE;
  8904. break;
  8905. }
  8906. }
  8907. }
  8908. else
  8909. isEmptyFile = TRUE;
  8910. fclose(fptr1);
  8911. if(isEmptyFile == TRUE)
  8912. {
  8913. memset(str, 0, ARRAY_SIZE(str));
  8914. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8915. system(str);
  8916. }
  8917. /*------- End of reading ---------------*/
  8918. }
  8919. } // while(int k=0; k < ChargeProfileCount; k++)
  8920. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8921. end:
  8922. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8923. {
  8924. if(connectorIdInt == 0)
  8925. {
  8926. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8927. {
  8928. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8929. }
  8930. }
  8931. else
  8932. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8933. }
  8934. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8935. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8936. return result;
  8937. }
  8938. void createFirmwareVersionByDataTransfer(void)
  8939. {
  8940. json_object *FirmwareDataTransfer = json_object_new_object();
  8941. // AC & DC model
  8942. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8943. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8944. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8945. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8946. // DC model
  8947. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8948. {
  8949. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8950. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8951. (gunType[3] != GUN_TYPE_UNKNOWN))
  8952. {
  8953. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8954. }
  8955. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8956. {
  8957. // DS DM DW
  8958. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8959. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8964. }
  8965. else
  8966. {
  8967. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8968. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8969. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8970. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8980. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8981. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8982. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8983. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8988. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8989. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8990. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8991. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8992. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8993. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8994. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8995. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8996. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8997. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8998. }
  8999. }
  9000. // 4G model
  9001. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9002. {
  9003. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9004. }
  9005. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9006. json_object_put(FirmwareDataTransfer);
  9007. }
  9008. int handleDataTransferRequest(char *uuid, char *payload)
  9009. {
  9010. mtrace();
  9011. json_object *response = json_object_new_object();
  9012. int result = FAIL;
  9013. char tempvendorId[255]={0};
  9014. char tempmessageId[50]={0};
  9015. char tempdata[512]={0};
  9016. char message[2048]={0};
  9017. DEBUG_INFO("handleDataTransferRequest...\n");
  9018. if((uuid != NULL) && (payload != NULL))
  9019. {
  9020. json_object *DataTransfer;
  9021. DataTransfer = json_tokener_parse(payload);
  9022. if(!is_error(DataTransfer))
  9023. {
  9024. // Required data
  9025. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9026. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9027. // Optional data
  9028. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9029. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9030. if(json_object_object_get(DataTransfer, "data") != NULL)
  9031. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9032. result = PASS;
  9033. }
  9034. json_object_put(DataTransfer);
  9035. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9036. {
  9037. // Send all moudle firmware version on EVSE
  9038. createFirmwareVersionByDataTransfer();
  9039. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9040. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9041. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9042. json_object_put(response);
  9043. }
  9044. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9045. {
  9046. system("/usr/bin/run_tmate_restart.sh &");
  9047. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9048. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9049. json_object_put(response);
  9050. }
  9051. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9052. {
  9053. json_object *data;
  9054. data = json_tokener_parse(tempdata);
  9055. if(!is_error(data))
  9056. {
  9057. 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))
  9058. {
  9059. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9060. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9061. if(json_object_object_get(data, "SOC") != NULL)
  9062. {
  9063. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9064. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9065. }
  9066. if(json_object_object_get(data, "Energy") != NULL)
  9067. {
  9068. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9069. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9070. }
  9071. if(json_object_object_get(data, "Duration") != NULL)
  9072. {
  9073. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9074. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9075. }
  9076. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9077. }
  9078. else
  9079. {
  9080. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9081. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9082. }
  9083. }
  9084. else
  9085. {
  9086. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9087. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9088. }
  9089. json_object_put(data);
  9090. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9091. json_object_put(response);
  9092. }
  9093. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9094. {
  9095. json_object *data;
  9096. data = json_tokener_parse(tempdata);
  9097. if(!is_error(data))
  9098. {
  9099. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9100. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9101. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9102. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9109. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9110. }
  9111. else
  9112. {
  9113. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9114. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9115. }
  9116. json_object_put(data);
  9117. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9118. json_object_put(response);
  9119. }
  9120. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9121. {
  9122. json_object *data;
  9123. data = json_tokener_parse(tempdata);
  9124. if(!is_error(data))
  9125. {
  9126. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9127. if(json_object_object_get(data, "idToken") != NULL)
  9128. {
  9129. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9130. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9131. }
  9132. if(json_object_object_get(data, "price") != NULL)
  9133. {
  9134. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9135. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9136. }
  9137. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9138. }
  9139. else
  9140. {
  9141. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9142. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9143. }
  9144. json_object_put(data);
  9145. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9146. json_object_put(response);
  9147. }
  9148. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9149. {
  9150. json_object *data;
  9151. data = json_tokener_parse(tempdata);
  9152. if(!is_error(data))
  9153. {
  9154. if(json_object_object_get(data, "txId") != NULL)
  9155. {
  9156. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9157. for(int idx = 0;idx<gunTotalNumber;idx++)
  9158. {
  9159. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9160. {
  9161. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9162. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9163. if(json_object_object_get(data, "description") != NULL)
  9164. {
  9165. // California pricing V1.0
  9166. DEBUG_INFO("California pricing V1.0\n");
  9167. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9168. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9169. }
  9170. else
  9171. {
  9172. // California pricing V1.1
  9173. DEBUG_INFO("California pricing V1.1\n");
  9174. if(json_object_object_get(data, "timestamp") != NULL)
  9175. {
  9176. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9177. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9178. }
  9179. if(json_object_object_get(data, "meterValue") != NULL)
  9180. {
  9181. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9182. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9183. }
  9184. if(json_object_object_get(data, "cost") != NULL)
  9185. {
  9186. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9187. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9188. }
  9189. if(json_object_object_get(data, "state") != NULL)
  9190. {
  9191. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9192. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9193. }
  9194. if(json_object_object_get(data, "chargingPrice") != NULL)
  9195. {
  9196. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9197. {
  9198. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9199. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9200. }
  9201. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9202. {
  9203. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9204. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9205. }
  9206. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9207. {
  9208. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9209. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9210. }
  9211. }
  9212. if(json_object_object_get(data, "idlePrice") != NULL)
  9213. {
  9214. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9215. {
  9216. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9217. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9218. }
  9219. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9220. {
  9221. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9222. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9223. }
  9224. }
  9225. if(json_object_object_get(data, "nextPeriod") != NULL)
  9226. {
  9227. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9228. {
  9229. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9230. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9231. }
  9232. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9233. {
  9234. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9235. {
  9236. 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")));
  9237. 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"));
  9238. }
  9239. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9240. {
  9241. 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")));
  9242. 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"));
  9243. }
  9244. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9245. {
  9246. 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")));
  9247. 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"));
  9248. }
  9249. }
  9250. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9251. {
  9252. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9253. {
  9254. 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")));
  9255. 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"));
  9256. }
  9257. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9258. {
  9259. 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")));
  9260. 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"));
  9261. }
  9262. }
  9263. }
  9264. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9265. {
  9266. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9267. {
  9268. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9269. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9270. }
  9271. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9272. {
  9273. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9274. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9275. }
  9276. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9277. {
  9278. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9279. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9280. }
  9281. }
  9282. }
  9283. }
  9284. }
  9285. }
  9286. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9287. }
  9288. else
  9289. {
  9290. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9291. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9292. }
  9293. json_object_put(data);
  9294. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9295. json_object_put(response);
  9296. }
  9297. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9298. {
  9299. json_object *data;
  9300. data = json_tokener_parse(tempdata);
  9301. if(!is_error(data))
  9302. {
  9303. if(json_object_object_get(data, "txId") != NULL)
  9304. {
  9305. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9306. for(int idx = 0;idx<gunTotalNumber;idx++)
  9307. {
  9308. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9309. {
  9310. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9311. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9312. if(json_object_object_get(data, "description") != NULL)
  9313. {
  9314. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9315. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9316. }
  9317. }
  9318. }
  9319. }
  9320. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9321. }
  9322. else
  9323. {
  9324. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9325. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9326. }
  9327. json_object_put(data);
  9328. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9329. json_object_put(response);
  9330. }
  9331. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9332. {
  9333. json_object *data;
  9334. data = json_tokener_parse(tempdata);
  9335. if(!is_error(data))
  9336. {
  9337. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9338. if(json_object_object_get(data, "Content_Type") != NULL)
  9339. {
  9340. 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))
  9341. {
  9342. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9343. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9344. {
  9345. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9346. }
  9347. }
  9348. else
  9349. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9350. }
  9351. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9352. }
  9353. else
  9354. {
  9355. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9356. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9357. }
  9358. json_object_put(data);
  9359. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9360. json_object_put(response);
  9361. }
  9362. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9363. {
  9364. json_object *data;
  9365. data = json_tokener_parse(tempdata);
  9366. if(!is_error(data))
  9367. {
  9368. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9369. if(json_object_object_get(data, "Page_Index") != NULL)
  9370. {
  9371. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9372. }
  9373. if(json_object_object_get(data, "Duration") != NULL)
  9374. {
  9375. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9376. }
  9377. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9378. }
  9379. else
  9380. {
  9381. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9382. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9383. }
  9384. json_object_put(data);
  9385. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9386. json_object_put(response);
  9387. }
  9388. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9389. {
  9390. json_object *data;
  9391. data = json_tokener_parse(tempdata);
  9392. if(!is_error(data))
  9393. {
  9394. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9395. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9396. {
  9397. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9398. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9399. else
  9400. {
  9401. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9402. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9403. }
  9404. }
  9405. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9406. {
  9407. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9408. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9409. else
  9410. {
  9411. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9412. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9413. }
  9414. }
  9415. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9416. {
  9417. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9418. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9419. else
  9420. {
  9421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9422. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9423. }
  9424. }
  9425. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9426. {
  9427. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9428. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9429. else
  9430. {
  9431. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9432. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9433. }
  9434. }
  9435. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9436. {
  9437. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9438. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9439. else
  9440. {
  9441. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9442. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9443. }
  9444. }
  9445. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9446. {
  9447. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9448. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9449. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9450. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9451. else
  9452. {
  9453. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9454. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9455. }
  9456. }
  9457. if(json_object_object_get(data, "isAuthentication") != NULL)
  9458. {
  9459. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9460. {
  9461. case 0:
  9462. case 1:
  9463. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9464. break;
  9465. default:
  9466. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9467. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9468. break;
  9469. }
  9470. }
  9471. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9472. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9473. }
  9474. else
  9475. {
  9476. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9477. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9478. }
  9479. json_object_put(data);
  9480. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9481. json_object_put(response);
  9482. }
  9483. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9484. {
  9485. json_object *data;
  9486. data = json_tokener_parse(tempdata);
  9487. if(!is_error(data))
  9488. {
  9489. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9490. {
  9491. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9492. {
  9493. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9494. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9495. }
  9496. else
  9497. {
  9498. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9499. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9500. }
  9501. }
  9502. else
  9503. {
  9504. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9505. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9506. }
  9507. }
  9508. else
  9509. {
  9510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9512. }
  9513. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9514. json_object_put(response);
  9515. }
  9516. else
  9517. {
  9518. // Can not find valid message id
  9519. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9520. }
  9521. }
  9522. else
  9523. {
  9524. // Payload is null
  9525. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9526. }
  9527. LWS_Send(message);
  9528. return result;
  9529. }
  9530. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9531. {
  9532. mtrace();
  9533. int result = FAIL;
  9534. int connectorIdInt, durationInt;
  9535. char chargingRateUnitStr[4]={0};
  9536. char comfirmstr[20];
  9537. int confirmPeriods = 0;
  9538. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9539. json_object *GetCompositeSchedule;
  9540. GetCompositeSchedule = json_tokener_parse(payload);
  9541. if(!is_error(GetCompositeSchedule))
  9542. {
  9543. // Required data
  9544. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9545. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9546. else
  9547. connectorIdInt = -1;
  9548. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9549. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9550. else
  9551. durationInt = 86400;
  9552. // Optional data
  9553. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9554. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9555. }
  9556. json_object_put(GetCompositeSchedule);
  9557. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9558. if((connectorIdInt == 0) ||
  9559. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9560. {
  9561. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9562. struct StructChargingProfile tmpProfile[1];
  9563. if(strstr(chargingRateUnitStr, "W") != NULL)
  9564. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9565. else
  9566. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9567. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9568. {
  9569. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9570. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9571. }
  9572. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9573. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9574. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9575. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9576. {
  9577. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9578. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9579. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9580. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9581. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9582. {
  9583. confirmPeriods = idx;
  9584. break;
  9585. }
  9586. }
  9587. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9588. {
  9589. confirmPeriods += 1;
  9590. }
  9591. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9592. }
  9593. else
  9594. {
  9595. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9596. }
  9597. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9598. return result;
  9599. }
  9600. int handleGetConfigurationRequest(char *uuid, char *payload)
  9601. {
  9602. mtrace();
  9603. int result = FAIL;
  9604. int MaxKeySupported = 0;
  9605. int n_keys = 0;
  9606. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9607. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9608. json_object *GetConfiguration;
  9609. GetConfiguration = json_tokener_parse(payload);
  9610. if(!is_error(GetConfiguration))
  9611. {
  9612. // Optional data
  9613. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9614. {
  9615. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9616. {
  9617. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9618. n_keys = idx + 1;
  9619. }
  9620. }
  9621. }
  9622. json_object_put(GetConfiguration);
  9623. UnknownKeynum = 0;
  9624. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9625. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9626. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9627. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9628. if(n_keys != 0)
  9629. {
  9630. for(int i=0;i<n_keys;i++)
  9631. {
  9632. getKeyValue(requestKey[i]);
  9633. }
  9634. }
  9635. else
  9636. {
  9637. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9638. getKeyValue("");
  9639. }
  9640. processUnkownKey();
  9641. sendGetConfigurationConfirmation(uuid);
  9642. return result;
  9643. }
  9644. static char fnamePlusPath[100]={0};
  9645. static char fnamePWithNoPath[60]={0};
  9646. void checkUploadLog(void)
  9647. {
  9648. FILE *fp;
  9649. /* Open the command for reading. */
  9650. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9651. if (fp == NULL) {
  9652. DEBUG_WARN("Failed to run command\n" );
  9653. exit(1);
  9654. }
  9655. int ftppathlen = 0;
  9656. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9657. int i = 0;
  9658. /* Read the output a line at a time - output it. */
  9659. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9660. if(i==0)
  9661. {
  9662. ftppathlen = strlen(fnamePlusPath);
  9663. DEBUG_INFO("%s\n", fnamePlusPath);
  9664. fnamePlusPath[ftppathlen]='\0';
  9665. break;
  9666. }
  9667. i= i+1;
  9668. }
  9669. /* close */
  9670. pclose(fp);
  9671. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9672. {
  9673. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9674. {
  9675. fnamePlusPath[k]='\0';
  9676. }
  9677. }
  9678. i=1;
  9679. //char fname[60]={0};
  9680. while(i < ftppathlen)
  9681. {
  9682. int len=ftppathlen-i;
  9683. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9684. {
  9685. DEBUG_INFO("compare '/' all right\n");
  9686. break;
  9687. }
  9688. i=i+1;
  9689. }
  9690. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9691. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9692. fnamePWithNoPath[i+1] = '\0';
  9693. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9694. {
  9695. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9696. {
  9697. fnamePWithNoPath[j]='\0';
  9698. }
  9699. }
  9700. FILE* fp1 = fopen(fnamePlusPath, "r");
  9701. if (fp1)
  9702. {
  9703. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9704. // file exists
  9705. fclose(fp1);
  9706. }
  9707. else
  9708. {
  9709. // file doesn't exist
  9710. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9711. }
  9712. }
  9713. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9714. {
  9715. mtrace();
  9716. int result = FAIL;
  9717. time_t CurrentTime;
  9718. struct tm *tm;
  9719. pthread_t th_Status;
  9720. CurrentTime = time(NULL);
  9721. tm = localtime(&CurrentTime);
  9722. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9723. 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);
  9724. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9725. if(!interLock.isGetDiagnosticGoing)
  9726. {
  9727. interLock.isGetDiagnosticGoing = 1;
  9728. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9729. sleep(1);
  9730. }
  9731. else
  9732. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9733. return result;
  9734. }
  9735. void* GetDiagnosticsProcess(void* data)
  9736. {
  9737. pthread_detach(pthread_self());
  9738. mtrace();
  9739. int retriesInt=0, retryIntervalInt=0;
  9740. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9741. 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};
  9742. int port=0;
  9743. int isSuccess = FALSE;
  9744. char cmdBuf[2048];
  9745. struct tm *tmNow;
  9746. time_t CurrentTime;
  9747. struct tm tmStart;
  9748. struct tm tmStop;
  9749. CurrentTime = time(NULL);
  9750. tmNow=localtime(&CurrentTime);
  9751. uint16_t targetYear, targetMonth;
  9752. json_object *GetDiagnostics;
  9753. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9754. GetDiagnostics = json_tokener_parse(data);
  9755. if(!is_error(GetDiagnostics))
  9756. {
  9757. // Required data
  9758. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9759. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9760. // Optional data
  9761. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9762. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9763. else
  9764. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9765. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9766. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9767. else
  9768. retryIntervalInt = 30;
  9769. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9770. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9771. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9772. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9773. }
  9774. json_object_put(GetDiagnostics);
  9775. // Pack log to compress file
  9776. 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) &&
  9777. (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))
  9778. {
  9779. // Pack system log
  9780. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9781. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9782. targetYear = tmStart.tm_year;
  9783. targetMonth = tmStart.tm_mon;
  9784. do
  9785. {
  9786. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9787. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9788. if(targetMonth+1>=13)
  9789. {
  9790. targetYear += 1;
  9791. targetMonth = 1;
  9792. }
  9793. else
  9794. {
  9795. targetMonth += 1;
  9796. }
  9797. }while((targetYear < (tmNow->tm_year+1900)) ||
  9798. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9799. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9800. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9801. system(cmdBuf);
  9802. // Pack charging & event log
  9803. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9804. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9805. targetYear = tmStart.tm_year;
  9806. targetMonth = tmStart.tm_mon;
  9807. do
  9808. {
  9809. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9810. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9811. if(targetMonth+1>=13)
  9812. {
  9813. targetYear += 1;
  9814. targetMonth = 1;
  9815. }
  9816. else
  9817. {
  9818. targetMonth += 1;
  9819. }
  9820. }while((targetYear < (tmNow->tm_year+1900)) ||
  9821. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9822. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9823. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9824. system(cmdBuf);
  9825. // Combine log file
  9826. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9827. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9828. }
  9829. else
  9830. {
  9831. system("exec /root/logPackTools 'log' 6");
  9832. }
  9833. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9834. system(cmdBuf);
  9835. checkUploadLog();
  9836. //****************location*******************/
  9837. if(strcmp(locationstr,"")==0)
  9838. {
  9839. DEBUG_INFO("location is <Empty>!\n");
  9840. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9841. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9842. goto end;
  9843. }
  9844. memset(protocol, 0, ARRAY_SIZE(protocol));
  9845. memset(user, 0, ARRAY_SIZE(user) );
  9846. memset(password, 0, ARRAY_SIZE(password));
  9847. memset(host, 0, ARRAY_SIZE(host));
  9848. memset(path, 0, ARRAY_SIZE(path));
  9849. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9850. memset(host1, 0, ARRAY_SIZE(host1));
  9851. memset(path1, 0, ARRAY_SIZE(path1));
  9852. /*location: ftp://user:password@host:port/path*/
  9853. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9854. if((access(fnamePlusPath,F_OK))!=-1)
  9855. {
  9856. DEBUG_INFO("fnamePlusPath exist.\n");
  9857. }
  9858. else
  9859. {
  9860. DEBUG_INFO("fnamePlusPath not exist!\n");
  9861. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9862. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9863. goto end;
  9864. }
  9865. if(strchr(locationstr,'@')==NULL)
  9866. {
  9867. sscanf(locationstr,
  9868. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9869. protocol, host, &port, path);
  9870. strcpy(user,"anonymous");
  9871. strcpy(password,"");
  9872. }
  9873. else
  9874. {
  9875. //DEBUG_INFO("pch=%s\n", pch);
  9876. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9877. protocol, user, password, host, &port, path);
  9878. }
  9879. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9880. {
  9881. DEBUG_INFO("protocol is not ftp/http ! \n");
  9882. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9883. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9884. goto end;
  9885. }
  9886. if(strncmp(locationstr,"http", 4) == 0)
  9887. {
  9888. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9889. sprintf(ftppath,"/%s", path);
  9890. do
  9891. {
  9892. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9893. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9894. sleep(3);
  9895. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9896. if(!isSuccess)
  9897. {
  9898. DEBUG_INFO("Diagnostics fail.\n");
  9899. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9900. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9901. sleep(retryIntervalInt);
  9902. }
  9903. else
  9904. {
  9905. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9906. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9907. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9908. }
  9909. retriesInt--;
  9910. }while((isSuccess == 0)&&(retriesInt >= 0));
  9911. }
  9912. else
  9913. {
  9914. sscanf(host,"%[^/]%s",host1, path1);
  9915. if(strlen(path) > 0)
  9916. sprintf(ftppath,"/%s", path);
  9917. else
  9918. sprintf(ftppath,"/%s", path1);
  9919. int ftppathlen=strlen(ftppath);
  9920. int i=1;
  9921. char filenametemp[50];
  9922. while(i < ftppathlen)
  9923. {
  9924. int len=ftppathlen-i;
  9925. if(ftppath[len]== 47) // '/' ascll code: 47
  9926. {
  9927. DEBUG_INFO("find '/' all right\n");
  9928. break;
  9929. }
  9930. i=i+1;
  9931. }
  9932. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9933. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9934. filenametemp[i+1] = 0;
  9935. if(port == 0)
  9936. port = 21;
  9937. do
  9938. {
  9939. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9940. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9941. sleep(3);
  9942. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9943. if(!isSuccess)
  9944. {
  9945. DEBUG_INFO("Diagnostics fail.\n");
  9946. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9947. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9948. sleep(retryIntervalInt);
  9949. }
  9950. else
  9951. {
  9952. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9953. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9954. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9955. }
  9956. retriesInt--;
  9957. }while((!isSuccess)&&(retriesInt >= 0));
  9958. }
  9959. end:
  9960. system("rm -f /mnt/*");
  9961. sleep(5);
  9962. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9963. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9964. interLock.isGetDiagnosticGoing = 0;
  9965. pthread_exit(NULL);
  9966. }
  9967. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9968. {
  9969. mtrace();
  9970. int result = FAIL;
  9971. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9972. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9973. {
  9974. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9975. locallistVersion = -1;
  9976. }
  9977. else
  9978. {
  9979. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9980. OCPP_getListVerion();
  9981. }
  9982. //from db.OCPP_getListVerion
  9983. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9984. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9985. sendGetLocalListVersionConfirmation(uuid,"");
  9986. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9987. return result;
  9988. }
  9989. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9990. {
  9991. mtrace();
  9992. int result = FAIL;
  9993. int connectorIdInt=-1;
  9994. int tempIndex = 0;
  9995. int connectorIdIsNULL, chargingProfileIsNULL;
  9996. char comfirmstr[20]={0};
  9997. char cmdBuf[512];
  9998. json_object *RemoteStartTransaction;
  9999. FILE *fp;
  10000. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10001. if(server_pending == TRUE)
  10002. {
  10003. return 0;
  10004. }
  10005. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10006. RemoteStartTransaction = json_tokener_parse(payload);
  10007. if(!is_error(RemoteStartTransaction))
  10008. {
  10009. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10010. {
  10011. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10012. }
  10013. else
  10014. {
  10015. connectorIdIsNULL = TRUE;
  10016. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10017. {
  10018. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10019. {
  10020. connectorIdIsNULL = FALSE;
  10021. connectorIdInt = (gun_index+1);
  10022. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10023. break;
  10024. }
  10025. }
  10026. }
  10027. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10028. {
  10029. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10030. // Required data
  10031. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10032. // Optional data
  10033. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10034. {
  10035. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10036. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10037. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10038. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10039. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10040. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10041. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10042. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10043. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10044. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10045. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10046. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10047. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10048. {
  10049. 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")));
  10050. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10051. 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"));
  10052. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10053. 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"));
  10054. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10055. 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")));
  10056. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10057. {
  10058. 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++)
  10059. {
  10060. 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"));
  10061. 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"));
  10062. 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)
  10063. 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"));
  10064. }
  10065. }
  10066. }
  10067. }
  10068. else
  10069. {
  10070. chargingProfileIsNULL = TRUE;
  10071. }
  10072. }
  10073. }
  10074. else
  10075. {
  10076. connectorIdIsNULL = TRUE;
  10077. }
  10078. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10079. {
  10080. DEBUG_WARN("Connector id is NULL\n.");
  10081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10082. goto end;
  10083. }
  10084. /*
  10085. enum _SYSTEM_STATUS
  10086. {
  10087. S_BOOTING = 0,
  10088. S_IDLE, = 1
  10089. S_AUTHORIZING, = 2
  10090. S_REASSIGN_CHECK, = 3
  10091. S_REASSIGN, = 4
  10092. S_PRECHARGE, = 5
  10093. S_PREPARING_FOR_EV, = 6
  10094. S_PREPARING_FOR_EVSE, = 7
  10095. S_CHARGING, = 8
  10096. S_TERMINATING, = 9
  10097. S_COMPLETE, = 10
  10098. S_ALARM, = 11
  10099. S_FAULT = 12
  10100. }
  10101. */
  10102. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10103. {
  10104. //check Transaction active
  10105. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10106. {
  10107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10108. {
  10109. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10110. }
  10111. else
  10112. {
  10113. tempIndex = connectorIdInt -1;
  10114. }
  10115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10116. {
  10117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10118. {
  10119. 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))
  10120. {
  10121. //Reserved
  10122. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10123. }
  10124. 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))
  10125. {
  10126. //Reserved
  10127. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10128. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10129. goto end;
  10130. }
  10131. else
  10132. {
  10133. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10134. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10135. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10136. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10137. {
  10138. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10140. goto end;
  10141. }
  10142. }//END FOR ELSE
  10143. }
  10144. }// END FOR CHAdeMO_QUANTITY
  10145. }
  10146. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10147. {
  10148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10149. {
  10150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10151. }
  10152. else
  10153. {
  10154. tempIndex = connectorIdInt -1;
  10155. }
  10156. for (int index = 0; index < CCS_QUANTITY; index++)
  10157. {
  10158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10159. {
  10160. 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))
  10161. {
  10162. //Reserved
  10163. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10164. }
  10165. 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))
  10166. {
  10167. //Reserved
  10168. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10169. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10170. goto end;
  10171. }
  10172. else
  10173. {
  10174. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10175. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10176. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10177. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10178. {
  10179. DEBUG_WARN("CCS connector not allow start\n.");
  10180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10181. goto end;
  10182. }
  10183. }// END FOR ELSE
  10184. }
  10185. }// END FOR CCS_QUANTITY
  10186. }
  10187. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10188. {
  10189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10190. {
  10191. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10192. }
  10193. else
  10194. {
  10195. tempIndex = connectorIdInt -1;
  10196. }
  10197. for (int index = 0; index < GB_QUANTITY; index++)
  10198. {
  10199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10200. {
  10201. 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))
  10202. {
  10203. //Reserved
  10204. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10205. }
  10206. 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))
  10207. {
  10208. //Reserved
  10209. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10210. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10211. goto end;
  10212. }
  10213. else
  10214. {
  10215. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10216. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10217. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10218. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10219. {
  10220. DEBUG_WARN("GB connector not allow start\n.");
  10221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10222. goto end;
  10223. }
  10224. }// END FOR ELSE
  10225. }
  10226. } // END FOR GB_QUANTITY
  10227. }
  10228. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10229. {
  10230. tempIndex = connectorIdInt -1;
  10231. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10232. {
  10233. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10234. {
  10235. 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))
  10236. {
  10237. //Reserved
  10238. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10239. }
  10240. 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))
  10241. {
  10242. //Reserved
  10243. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10245. goto end;
  10246. }
  10247. else
  10248. {
  10249. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10250. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10251. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10252. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10253. {
  10254. DEBUG_WARN("GB connector not allow start\n.");
  10255. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10256. goto end;
  10257. }
  10258. }// END FOR ELSE
  10259. }
  10260. } // END FOR GB_QUANTITY
  10261. }
  10262. else
  10263. {
  10264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10265. {
  10266. tempIndex = 2;
  10267. }
  10268. else
  10269. {
  10270. tempIndex = connectorIdInt -1;
  10271. }
  10272. for (int index = 0; index < AC_QUANTITY; index++)
  10273. {
  10274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10275. {
  10276. 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))
  10277. {
  10278. //Reserved
  10279. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10280. }
  10281. 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))
  10282. {
  10283. //Reserved
  10284. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10286. goto end;
  10287. }
  10288. else
  10289. {
  10290. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10291. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10292. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10293. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10294. {
  10295. DEBUG_WARN("AC connector not allow start\n.");
  10296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10297. goto end;
  10298. }
  10299. }//END FOR ELSE
  10300. }
  10301. }// END FOR AC_QUANTITY
  10302. }
  10303. if(chargingProfileIsNULL == FALSE)
  10304. {
  10305. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10306. {
  10307. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10308. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10309. //memset idTag
  10310. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10311. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10312. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10313. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10314. // Save profile to file
  10315. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10316. system(cmdBuf);
  10317. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10318. fp = fopen(cmdBuf, "w");
  10319. 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));
  10320. fclose(fp);
  10321. }
  10322. else
  10323. {
  10324. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10326. }
  10327. }
  10328. else
  10329. {
  10330. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10332. //memset idTag
  10333. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10334. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10335. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10336. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10337. }
  10338. }
  10339. else
  10340. {
  10341. DEBUG_WARN("Connector id over\n.");
  10342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10343. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10344. }
  10345. end:
  10346. json_object_put(RemoteStartTransaction);
  10347. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10348. {
  10349. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10350. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10351. }
  10352. //OCPP send RemoteStartConfirmation by first.
  10353. sendRemoteStartConfirmation(uuid, comfirmstr);
  10354. return result;
  10355. }
  10356. int handleRemoteStartRequest(char *uuid, char *payload)
  10357. {
  10358. mtrace();
  10359. int result = PASS;
  10360. int connectorIdInt=-1;
  10361. int tempIndex = 0;
  10362. char comfirmstr[20]={0};
  10363. char cmdBuf[512];
  10364. json_object *RemoteStartTransaction;
  10365. FILE *fp;
  10366. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10367. if(server_pending == TRUE)
  10368. {
  10369. result = FAIL;
  10370. }
  10371. RemoteStartTransaction = json_tokener_parse(payload);
  10372. if(!is_error(RemoteStartTransaction))
  10373. {
  10374. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10375. {
  10376. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10377. }
  10378. else
  10379. {
  10380. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10381. {
  10382. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10383. {
  10384. connectorIdInt = (gun_index+1);
  10385. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10386. break;
  10387. }
  10388. }
  10389. }
  10390. if(connectorIdInt == 0)
  10391. {
  10392. DEBUG_WARN("Connector id shall not equal 0.\n");
  10393. result = FAIL;
  10394. }
  10395. else if(connectorIdInt == -1)
  10396. {
  10397. DEBUG_INFO("Connector id does not specific.\n");
  10398. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10399. {
  10400. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10401. // Required data
  10402. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10403. // Optional data
  10404. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10405. {
  10406. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10407. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10408. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10409. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10410. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10411. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10412. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10413. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10415. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10417. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10418. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10419. {
  10420. 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")));
  10421. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10422. 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"));
  10423. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10424. 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"));
  10425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10426. 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")));
  10427. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10428. {
  10429. 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++)
  10430. {
  10431. 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"));
  10432. 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"));
  10433. 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)
  10434. 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"));
  10435. }
  10436. }
  10437. }
  10438. }
  10439. else
  10440. {
  10441. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10442. }
  10443. }
  10444. }
  10445. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10446. {
  10447. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10448. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10449. // Required data
  10450. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10451. // Optional data
  10452. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10453. {
  10454. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10455. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10456. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10457. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10458. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10459. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10460. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10461. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10462. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10463. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10464. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10465. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10466. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10467. {
  10468. 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")));
  10469. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10470. 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"));
  10471. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10472. 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"));
  10473. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10474. 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")));
  10475. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10476. {
  10477. 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++)
  10478. {
  10479. 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"));
  10480. 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"));
  10481. 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)
  10482. 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"));
  10483. }
  10484. }
  10485. }
  10486. }
  10487. else
  10488. {
  10489. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10490. }
  10491. }
  10492. else
  10493. {
  10494. DEBUG_WARN("Connector id is over maximun value.\n");
  10495. result = FAIL;
  10496. }
  10497. }
  10498. if(result == PASS)
  10499. {
  10500. if(connectorIdInt > 0)
  10501. {
  10502. //check Transaction active
  10503. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10504. {
  10505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10506. {
  10507. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10508. }
  10509. else
  10510. {
  10511. tempIndex = connectorIdInt -1;
  10512. }
  10513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10514. {
  10515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10516. {
  10517. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10518. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10519. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10520. {
  10521. //Reserved
  10522. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10523. }
  10524. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10525. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10526. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10527. {
  10528. //Reserved
  10529. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10531. goto end;
  10532. }
  10533. else
  10534. {
  10535. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10536. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10537. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10538. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10539. {
  10540. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10542. goto end;
  10543. }
  10544. }//END FOR ELSE
  10545. }
  10546. }// END FOR CHAdeMO_QUANTITY
  10547. }
  10548. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10549. {
  10550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10551. {
  10552. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10553. }
  10554. else
  10555. {
  10556. tempIndex = connectorIdInt -1;
  10557. }
  10558. for (int index = 0; index < CCS_QUANTITY; index++)
  10559. {
  10560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10561. {
  10562. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10564. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10565. {
  10566. //Reserved
  10567. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10568. }
  10569. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10571. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10572. {
  10573. //Reserved
  10574. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10576. goto end;
  10577. }
  10578. else
  10579. {
  10580. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10581. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10582. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10583. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10584. {
  10585. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10586. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10587. goto end;
  10588. }
  10589. }// END FOR ELSE
  10590. }
  10591. }// END FOR CCS_QUANTITY
  10592. }
  10593. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10594. {
  10595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10596. {
  10597. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10598. }
  10599. else
  10600. {
  10601. tempIndex = connectorIdInt -1;
  10602. }
  10603. for (int index = 0; index < GB_QUANTITY; index++)
  10604. {
  10605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10606. {
  10607. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10608. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10609. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10610. {
  10611. //Reserved
  10612. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10613. }
  10614. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10615. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10616. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10617. {
  10618. //Reserved
  10619. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10620. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10621. goto end;
  10622. }
  10623. else
  10624. {
  10625. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10626. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10627. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10628. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10629. {
  10630. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10632. goto end;
  10633. }
  10634. }// END FOR ELSE
  10635. }
  10636. } // END FOR GB_QUANTITY
  10637. }
  10638. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10639. {
  10640. tempIndex = connectorIdInt -1;
  10641. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10642. {
  10643. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10644. {
  10645. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10646. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10647. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10648. {
  10649. //Reserved
  10650. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10651. }
  10652. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10653. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10654. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10655. {
  10656. //Reserved
  10657. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10658. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10659. goto end;
  10660. }
  10661. else
  10662. {
  10663. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10664. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10665. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10666. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10667. {
  10668. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10670. goto end;
  10671. }
  10672. }// END FOR ELSE
  10673. }
  10674. } // END FOR GB_QUANTITY
  10675. }
  10676. else
  10677. {
  10678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10679. {
  10680. tempIndex = 2;
  10681. }
  10682. else
  10683. {
  10684. tempIndex = connectorIdInt -1;
  10685. }
  10686. for (int index = 0; index < AC_QUANTITY; index++)
  10687. {
  10688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10689. {
  10690. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10691. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10692. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10693. {
  10694. //Reserved
  10695. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10696. }
  10697. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10698. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10699. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10700. {
  10701. //Reserved
  10702. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10704. goto end;
  10705. }
  10706. else
  10707. {
  10708. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10709. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10710. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10711. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10712. {
  10713. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. }//END FOR ELSE
  10718. }
  10719. }// END FOR AC_QUANTITY
  10720. }
  10721. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10722. {
  10723. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10724. {
  10725. // Save profile to file
  10726. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10727. system(cmdBuf);
  10728. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10729. fp = fopen(cmdBuf, "w");
  10730. 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));
  10731. fclose(fp);
  10732. }
  10733. else
  10734. {
  10735. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10737. goto end;
  10738. }
  10739. }
  10740. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10742. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10743. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10744. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10745. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10746. }
  10747. else
  10748. {
  10749. uint8_t isHasIdleConnector = FALSE;
  10750. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10751. {
  10752. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10753. {
  10754. isHasIdleConnector = TRUE;
  10755. break;
  10756. }
  10757. }
  10758. if(isHasIdleConnector == TRUE)
  10759. {
  10760. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10761. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10762. {
  10763. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10764. {
  10765. // Save profile to file
  10766. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10767. system(cmdBuf);
  10768. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10769. fp = fopen(cmdBuf, "w");
  10770. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10771. fclose(fp);
  10772. refreshStartTimer(&clientTime.RemoteStartWait);
  10773. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10775. }
  10776. else
  10777. {
  10778. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10779. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10780. }
  10781. }
  10782. else
  10783. {
  10784. refreshStartTimer(&clientTime.RemoteStartWait);
  10785. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10787. }
  10788. }
  10789. else
  10790. {
  10791. DEBUG_INFO("There is not any connector is idle.\n");
  10792. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10793. }
  10794. }
  10795. }
  10796. else
  10797. {
  10798. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10799. }
  10800. end:
  10801. json_object_put(RemoteStartTransaction);
  10802. sendRemoteStartConfirmation(uuid, comfirmstr);
  10803. return result;
  10804. }
  10805. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10806. {
  10807. mtrace();
  10808. int result = FAIL;
  10809. int match = FALSE;
  10810. int GunNO = 0;
  10811. int tempIndex = 0;
  10812. int transactionIdInt=0;
  10813. int transactionIdIsNULL= TRUE;
  10814. char comfirmstr[20];
  10815. json_object *RemoteStopTransaction;
  10816. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10817. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10818. if(server_pending == TRUE)
  10819. {
  10820. return 0;
  10821. }
  10822. RemoteStopTransaction = json_tokener_parse(payload);
  10823. if(!is_error(RemoteStopTransaction))
  10824. {
  10825. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10826. {
  10827. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10828. transactionIdIsNULL = FALSE;
  10829. }
  10830. }
  10831. json_object_put(RemoteStopTransaction);
  10832. if(transactionIdIsNULL == FALSE)
  10833. {
  10834. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10835. {
  10836. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10837. {
  10838. //check Transaction active
  10839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10840. {
  10841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10842. {
  10843. tempIndex = ((gun_index==2) ? 1: 0);
  10844. }
  10845. else
  10846. {
  10847. tempIndex = gun_index;
  10848. }
  10849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10850. {
  10851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10852. {
  10853. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10854. {
  10855. match = TRUE;
  10856. GunNO = gun_index;
  10857. }
  10858. }
  10859. }// END FOR CHAdeMO_QUANTITY
  10860. }
  10861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10862. {
  10863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10864. {
  10865. tempIndex = ((gun_index==2) ? 1: 0);
  10866. }
  10867. else
  10868. {
  10869. tempIndex = gun_index;
  10870. }
  10871. for (int index = 0; index < CCS_QUANTITY; index++)
  10872. {
  10873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10874. {
  10875. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10876. {
  10877. match = TRUE;
  10878. GunNO = gun_index;
  10879. }
  10880. }
  10881. }// END FOR CCS_QUANTITY
  10882. }
  10883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10884. {
  10885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10886. {
  10887. tempIndex = ((gun_index==2) ? 1: 0);
  10888. }
  10889. else
  10890. {
  10891. tempIndex = gun_index;
  10892. }
  10893. for (int index = 0; index < GB_QUANTITY; index++)
  10894. {
  10895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10896. {
  10897. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10898. {
  10899. match = TRUE;
  10900. GunNO = gun_index;
  10901. }
  10902. }
  10903. }// END FOR GB_QUANTITY
  10904. }
  10905. else if(gunType[gun_index] == GUN_TYPE_DO)
  10906. {
  10907. tempIndex = gun_index;
  10908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10909. {
  10910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10911. {
  10912. 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
  10913. {
  10914. match = TRUE;
  10915. GunNO = gun_index;
  10916. }
  10917. }
  10918. }// END FOR GB_QUANTITY
  10919. }
  10920. else
  10921. {
  10922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10923. {
  10924. tempIndex = 2;
  10925. }
  10926. else
  10927. {
  10928. tempIndex = gun_index;
  10929. }
  10930. for (int index = 0; index < AC_QUANTITY; index++)
  10931. {
  10932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10933. {
  10934. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10935. {
  10936. match = TRUE;
  10937. GunNO = gun_index;
  10938. }
  10939. }
  10940. }// END FOR CHAdeMO_QUANTITY
  10941. } // END FOR AC ELSE
  10942. }// CHECK IF ResponseTransactionId == transactionIdInt
  10943. }//END FOR
  10944. if( match == TRUE)
  10945. {
  10946. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10947. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10948. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10949. }
  10950. else
  10951. {
  10952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10953. }
  10954. }
  10955. else
  10956. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10957. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10958. return result;
  10959. }
  10960. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10961. {
  10962. mtrace();
  10963. int result = FAIL;
  10964. int connectorIdInt=0, reservationIdInt=0;
  10965. int tempIndex = 0;
  10966. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10967. char comfirmstr[20]={0};
  10968. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10969. int c = 0;
  10970. char *loc;
  10971. //char *ptr;
  10972. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10973. strcpy(sstrtemp, stringtrimspace(payload));
  10974. //***(1)connectorId ****/
  10975. c=0;
  10976. loc = strstr(sstrtemp, "connectorId");
  10977. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10978. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10979. {
  10980. sstr[c] = loc[strlen("connectorId")+2+c];
  10981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10982. c++;
  10983. }
  10984. sstr[c] = '\0';
  10985. connectorIdInt = atoi(sstr);
  10986. //***(2)expiryDate ****/
  10987. loc = strstr(sstrtemp, "expiryDate");
  10988. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10989. c = 0;
  10990. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10991. {
  10992. sstr[c] = loc[3+strlen("expiryDate")+c];
  10993. c++;
  10994. }
  10995. sstr[c] = '\0';
  10996. strcpy(expiryDatestr, sstr);
  10997. //***(3)idTag ****/
  10998. loc = strstr(sstrtemp, "idTag");
  10999. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11000. c = 0;
  11001. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11002. {
  11003. sstr[c] = loc[3+strlen("idTag")+c];
  11004. c++;
  11005. }
  11006. sstr[c] = '\0';
  11007. strcpy(idTagstr, sstr);
  11008. //***(4)parentIdTag ****/
  11009. loc = strstr(sstrtemp, "parentIdTag");
  11010. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11011. c = 0;
  11012. if(loc == NULL)
  11013. {
  11014. strcpy(parentIdTagstr, "");
  11015. }
  11016. else
  11017. {
  11018. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11019. {
  11020. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11021. c++;
  11022. }
  11023. sstr[c] = '\0';
  11024. strcpy(parentIdTagstr, sstr);
  11025. }
  11026. //***(5)reservationId ****/
  11027. c=0;
  11028. loc = strstr(sstrtemp, "reservationId");
  11029. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11030. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11031. {
  11032. sstr[c] = loc[strlen("reservationId")+2+c];
  11033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11034. c++;
  11035. }
  11036. sstr[c] = '\0';
  11037. reservationIdInt = atoi(sstr);
  11038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11039. /*
  11040. enum SYSTEM_STATUS
  11041. {
  11042. SYS_MODE_BOOTING = 0,
  11043. SYS_MODE_IDLE = 1,
  11044. SYS_MODE_AUTHORIZING = 2,
  11045. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11046. SYS_MODE_REASSIGN = 4,
  11047. SYS_MODE_PREPARING = 5,
  11048. SYS_MODE_PREPARE_FOR_EV = 6,
  11049. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11050. SYS_MODE_CHARGING = 8,
  11051. SYS_MODE_TERMINATING = 9,
  11052. SYS_MODE_COMPLETE = 10,
  11053. SYS_MODE_ALARM = 11,
  11054. SYS_MODE_FAULT = 12,
  11055. SYS_MODE_RESERVATION = 13,
  11056. SYS_MODE_BOOKING = 14,
  11057. SYS_MODE_MAINTAIN = 15,
  11058. SYS_MODE_DEBUG = 16,
  11059. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11060. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11061. SYS_MODE_UPDATE = 19
  11062. };
  11063. */
  11064. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11065. {
  11066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11067. goto end;
  11068. }
  11069. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11070. {
  11071. //check Transaction active
  11072. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11073. {
  11074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11075. {
  11076. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11077. }
  11078. else
  11079. {
  11080. tempIndex = connectorIdInt -1;
  11081. }
  11082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11083. {
  11084. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11085. {
  11086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11087. {
  11088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11089. {
  11090. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11091. {
  11092. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11094. }
  11095. 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'))
  11096. {
  11097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11098. }
  11099. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11100. {
  11101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11102. }
  11103. else
  11104. {
  11105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11106. }
  11107. }
  11108. 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
  11109. {
  11110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11111. }
  11112. }
  11113. else
  11114. {
  11115. //replace reservation
  11116. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11118. }
  11119. }
  11120. } // END FOR CHAdeMO_QUANTITY
  11121. }
  11122. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11123. {
  11124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11125. {
  11126. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11127. }
  11128. else
  11129. {
  11130. tempIndex = connectorIdInt -1;
  11131. }
  11132. for (int index = 0; index < CCS_QUANTITY; index++)
  11133. {
  11134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11135. {
  11136. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11137. {
  11138. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11140. {
  11141. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11142. {
  11143. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11145. }
  11146. 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'))
  11147. {
  11148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11149. }
  11150. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11151. {
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11153. }
  11154. else
  11155. {
  11156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11157. }
  11158. }
  11159. 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
  11160. {
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11162. }
  11163. }
  11164. else
  11165. {
  11166. //replace reservation
  11167. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11169. }
  11170. }
  11171. } // END FOR CCS_QUANTITY
  11172. }
  11173. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11174. {
  11175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11176. {
  11177. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11178. }
  11179. else
  11180. {
  11181. tempIndex = connectorIdInt -1;
  11182. }
  11183. for (int index = 0; index < GB_QUANTITY; index++)
  11184. {
  11185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11186. {
  11187. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11188. {
  11189. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11190. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11191. {
  11192. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11193. {
  11194. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11196. }
  11197. 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'))
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11200. }
  11201. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11204. }
  11205. else
  11206. {
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11208. }
  11209. }
  11210. 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
  11211. {
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11213. }
  11214. }
  11215. else
  11216. {
  11217. //replace reservation
  11218. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11220. }
  11221. }
  11222. }// END FOR GB_QUANTITY
  11223. }
  11224. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11225. {
  11226. tempIndex = connectorIdInt -1;
  11227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11228. {
  11229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11230. {
  11231. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11232. {
  11233. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11234. 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
  11235. {
  11236. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11237. {
  11238. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11239. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11240. }
  11241. 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'))
  11242. {
  11243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11244. }
  11245. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11246. {
  11247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11248. }
  11249. else
  11250. {
  11251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11252. }
  11253. }
  11254. 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
  11255. {
  11256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11257. }
  11258. }
  11259. else
  11260. {
  11261. //replace reservation
  11262. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11264. }
  11265. }
  11266. }// END FOR GB_QUANTITY
  11267. }
  11268. else
  11269. {
  11270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11271. {
  11272. tempIndex = 2;
  11273. }
  11274. else
  11275. {
  11276. tempIndex = (connectorIdInt -1);
  11277. }
  11278. for (int index = 0; index < AC_QUANTITY; index++)
  11279. {
  11280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11281. {
  11282. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11283. {
  11284. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11285. {
  11286. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11287. {
  11288. 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))
  11289. {
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11291. }
  11292. else
  11293. {
  11294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11296. }
  11297. }
  11298. 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'))
  11299. {
  11300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11301. }
  11302. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11303. {
  11304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11305. }
  11306. else
  11307. {
  11308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11309. }
  11310. }
  11311. 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
  11312. {
  11313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11314. }
  11315. }
  11316. else
  11317. {
  11318. //replace reservation
  11319. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11321. }
  11322. }
  11323. } // END FOR AC_QUANTITY
  11324. }
  11325. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11326. }
  11327. else if(connectorIdInt == 0)
  11328. {
  11329. //check Transaction active
  11330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11331. {
  11332. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11333. {
  11334. 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'))
  11335. {
  11336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11337. goto end;
  11338. }
  11339. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11340. {
  11341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11342. goto end;
  11343. }
  11344. 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
  11345. {
  11346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11347. goto end;
  11348. }
  11349. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11350. {
  11351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11352. goto end;
  11353. }
  11354. }
  11355. }// END FOR CHAdeMO_QUANTITY
  11356. for (int index = 0; index < CCS_QUANTITY; index++)
  11357. {
  11358. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11359. {
  11360. 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'))
  11361. {
  11362. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11363. goto end;
  11364. }
  11365. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11366. {
  11367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11368. goto end;
  11369. }
  11370. 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
  11371. {
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11373. goto end;
  11374. }
  11375. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11376. {
  11377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11378. goto end;
  11379. }
  11380. }
  11381. } // END FOR CCS_QUANTITY
  11382. for (int index = 0; index < GB_QUANTITY; index++)
  11383. {
  11384. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11385. {
  11386. 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'))
  11387. {
  11388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11389. goto end;
  11390. }
  11391. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11392. {
  11393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11394. goto end;
  11395. }
  11396. 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
  11397. {
  11398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11399. goto end;
  11400. }
  11401. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11402. {
  11403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11404. goto end;
  11405. }
  11406. }
  11407. } // END FOR GB_QUANTITY
  11408. for (int index = 0; index < AC_QUANTITY; index++)
  11409. {
  11410. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11411. {
  11412. 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'))
  11413. {
  11414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11415. goto end;
  11416. }
  11417. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11418. {
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11420. goto end;
  11421. }
  11422. 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
  11423. {
  11424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11425. goto end;
  11426. }
  11427. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11428. {
  11429. 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))
  11430. {
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11432. goto end;
  11433. }
  11434. }
  11435. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11438. goto end;
  11439. }
  11440. }
  11441. }// END FOR AC_QUANTITY
  11442. //The connectorId is 0
  11443. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11445. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11446. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11447. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11448. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11449. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11450. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11451. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11452. result = TRUE;
  11453. return result;
  11454. }
  11455. else
  11456. {
  11457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11458. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11459. }
  11460. if(strcmp(comfirmstr,"Accepted") == 0)
  11461. {
  11462. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11463. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11464. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11465. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11466. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11467. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11468. result = TRUE;
  11469. return result;
  11470. }
  11471. end:
  11472. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11473. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11474. return result;
  11475. }
  11476. int handleResetRequest(char *uuid, char *payload)
  11477. {
  11478. mtrace();
  11479. int result = FAIL;
  11480. char sstr[10]={0},sstrtemp[30]={ 0 };
  11481. char typestr[10]={0};
  11482. char comfirmstr[20]={0};
  11483. int c = 0;
  11484. char *loc;
  11485. DEBUG_INFO("handleResetRequest...\n");
  11486. strcpy(sstrtemp, stringtrimspace(payload));
  11487. loc = strstr(sstrtemp, "type");
  11488. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11489. c = 0;
  11490. while (loc[3+strlen("type")+c] != '\"')
  11491. {
  11492. sstr[c] = loc[3+strlen("type")+c];
  11493. c++;
  11494. }
  11495. sstr[c] = '\0';
  11496. strcpy(typestr,sstr);
  11497. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11498. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11499. {
  11500. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11501. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11502. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11503. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11504. }
  11505. else
  11506. {
  11507. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11508. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11509. result = PASS;
  11510. }
  11511. sendResetConfirmation(uuid, comfirmstr);
  11512. return result;
  11513. }
  11514. int handleSendLocalListRequest(char *uuid, char *payload)
  11515. {
  11516. mtrace();
  11517. int result = FAIL;
  11518. char comfirmstr[20];
  11519. int checkState_Faulted = FALSE;
  11520. json_object *SendLocalList;
  11521. DEBUG_INFO("handleSendLocalListRequest...\n");
  11522. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11523. {
  11524. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11525. goto end;
  11526. }
  11527. //check Charge Point state
  11528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11529. {
  11530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11531. {
  11532. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11533. }
  11534. }
  11535. for (int index = 0; index < CCS_QUANTITY; index++)
  11536. {
  11537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11538. {
  11539. checkState_Faulted = TRUE; //OCPP Status
  11540. }
  11541. }
  11542. for (int index = 0; index < GB_QUANTITY; index++)
  11543. {
  11544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11545. {
  11546. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11547. }
  11548. }
  11549. //check Charge Point state
  11550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11551. {
  11552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11553. {
  11554. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11555. }
  11556. }
  11557. //check Charge Point state
  11558. for (int index = 0; index < AC_QUANTITY; index++)
  11559. {
  11560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11561. {
  11562. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11563. }
  11564. }
  11565. if(checkState_Faulted == TRUE)
  11566. {
  11567. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11568. goto end;
  11569. }
  11570. // Parsing payload
  11571. SendLocalList = json_tokener_parse(payload);
  11572. if(!is_error(SendLocalList))
  11573. {
  11574. // Required data
  11575. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11576. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11577. // Optional data
  11578. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11579. {
  11580. //Check UpdateType
  11581. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11582. {
  11583. //Local list full update
  11584. DEBUG_INFO("Local list full update.\n");
  11585. OCPP_getListVerion();
  11586. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11587. {
  11588. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11589. goto end;
  11590. }
  11591. OCPP_cleanLocalList();
  11592. }
  11593. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11594. {
  11595. //Local list different update
  11596. DEBUG_INFO("Local list different update.\n");
  11597. OCPP_getListVerion();
  11598. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11599. {
  11600. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11601. goto end;
  11602. }
  11603. }
  11604. else
  11605. {
  11606. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11607. goto end;
  11608. }
  11609. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11610. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11611. {
  11612. 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")));
  11613. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11614. {
  11615. 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")));
  11616. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11617. 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")));
  11618. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11619. 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")));
  11620. }
  11621. // Add to db
  11622. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11623. {
  11624. //Local list full update
  11625. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11626. idx,
  11627. ShmOCPP16Data->SendLocalList.ListVersion,
  11628. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11629. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11630. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11631. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11632. // update list
  11633. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11634. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11635. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11636. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11637. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11638. }
  11639. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11640. {
  11641. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11642. idx,
  11643. ShmOCPP16Data->SendLocalList.ListVersion,
  11644. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11645. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11646. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11647. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11648. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11649. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11650. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11651. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11652. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11653. }
  11654. }
  11655. }
  11656. else
  11657. {
  11658. //Check UpdateType
  11659. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11660. {
  11661. //Local list full update
  11662. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11663. OCPP_cleanLocalList();
  11664. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11665. goto end;
  11666. }
  11667. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11668. {
  11669. //Local list different update
  11670. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11671. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11672. goto end;
  11673. }
  11674. }
  11675. result = PASS;
  11676. }
  11677. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11678. end:
  11679. json_object_put(SendLocalList);
  11680. sendSendLocalListConfirmation(uuid, comfirmstr);
  11681. return result;
  11682. }
  11683. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11684. {
  11685. mtrace();
  11686. int result = FAIL;
  11687. struct StructSetChargingProfile SetProfileReq = {0};
  11688. int tempchargingProfileIdInt;
  11689. int chargingSchedulePeriodCount = 0;
  11690. char comfirmstr[20]={0};
  11691. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11692. char rmFileCmd[128]={0};
  11693. int profileQuantity = 0;
  11694. json_object *SetChargingProfile;
  11695. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11696. SetChargingProfile = json_tokener_parse(payload);
  11697. if(!is_error(SetChargingProfile))
  11698. {
  11699. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11700. {
  11701. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11702. }
  11703. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11704. {
  11705. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11706. {
  11707. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11708. }
  11709. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11710. {
  11711. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11712. }
  11713. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11714. {
  11715. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11716. }
  11717. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11718. {
  11719. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11720. }
  11721. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11722. {
  11723. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11724. }
  11725. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11726. {
  11727. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11728. }
  11729. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11730. {
  11731. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11732. }
  11733. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11734. {
  11735. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11736. }
  11737. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11738. {
  11739. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11740. {
  11741. 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")));
  11742. }
  11743. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11744. {
  11745. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11746. }
  11747. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11748. {
  11749. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11750. }
  11751. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11752. {
  11753. 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")));
  11754. }
  11755. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11756. {
  11757. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11758. if(chargingSchedulePeriodCount <= 10)
  11759. {
  11760. 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++)
  11761. {
  11762. 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)
  11763. {
  11764. 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"));
  11765. }
  11766. 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)
  11767. {
  11768. 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"));
  11769. }
  11770. 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)
  11771. {
  11772. 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"));
  11773. }
  11774. }
  11775. }
  11776. }
  11777. }
  11778. }
  11779. }
  11780. // Profile periods quantity check
  11781. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11782. {
  11783. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11784. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11785. goto end;
  11786. }
  11787. // Check invalid limit
  11788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11789. {
  11790. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11791. {
  11792. 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)))) ||
  11793. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11794. {
  11795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11796. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11797. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11798. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11799. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11800. goto end;
  11801. }
  11802. }
  11803. }
  11804. else
  11805. {
  11806. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11807. {
  11808. 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))
  11809. {
  11810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11811. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11812. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11813. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11814. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11815. goto end;
  11816. }
  11817. }
  11818. }
  11819. // Profile purpose info check
  11820. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11821. {
  11822. FILE *fp;
  11823. char dataLine[4096]={0};
  11824. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11825. if(SetProfileReq.ConnectorId != 0)
  11826. {
  11827. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11828. DEBUG_WARN("Profile connector id is not 0.\n");
  11829. goto end;
  11830. }
  11831. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11832. if (!fp)
  11833. {
  11834. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11835. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11836. }
  11837. else
  11838. {
  11839. while(fscanf(fp, "%s", dataLine) != EOF)
  11840. {
  11841. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11842. {
  11843. profileQuantity += 1;
  11844. }
  11845. }
  11846. }
  11847. fclose(fp);
  11848. }
  11849. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11850. {
  11851. FILE *fp;
  11852. char dataLine[4096]={0};
  11853. char filename[128]={0};
  11854. int tmpProfileQuantity;
  11855. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11856. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11857. {
  11858. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11859. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11860. goto end;
  11861. }
  11862. if(SetProfileReq.ConnectorId == 0)
  11863. {
  11864. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11865. {
  11866. tmpProfileQuantity = 0;
  11867. memset(filename, 0, ARRAY_SIZE(filename));
  11868. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11869. fp = fopen(filename, "r");
  11870. if (!fp)
  11871. {
  11872. DEBUG_INFO("%s does not create.\n", filename);
  11873. fp = fopen(filename, "w+");
  11874. }
  11875. else
  11876. {
  11877. while(fscanf(fp, "%s", dataLine) != EOF)
  11878. {
  11879. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11880. {
  11881. tmpProfileQuantity += 1;
  11882. }
  11883. }
  11884. }
  11885. fclose(fp);
  11886. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11887. }
  11888. }
  11889. else
  11890. {
  11891. memset(filename, 0, ARRAY_SIZE(filename));
  11892. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11893. fp = fopen(filename, "r");
  11894. if (!fp)
  11895. {
  11896. DEBUG_INFO("%s does not create.\n", filename);
  11897. fp = fopen(filename, "w+");
  11898. }
  11899. else
  11900. {
  11901. while(fscanf(fp, "%s", dataLine) != EOF)
  11902. {
  11903. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11904. {
  11905. profileQuantity += 1;
  11906. }
  11907. }
  11908. }
  11909. fclose(fp);
  11910. }
  11911. }
  11912. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11913. {
  11914. int isMatchTransactiodId= FALSE;
  11915. FILE *fp;
  11916. char dataLine[4096]={0};
  11917. char filename[128]={0};
  11918. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11919. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11920. if(SetProfileReq.ConnectorId == 0)
  11921. {
  11922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11923. DEBUG_WARN("Profile connector id is 0.\n");
  11924. goto end;
  11925. }
  11926. int tempIndex = 0;
  11927. //check Transaction active
  11928. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11929. {
  11930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11931. {
  11932. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11933. }
  11934. else
  11935. {
  11936. tempIndex = SetProfileReq.ConnectorId -1;
  11937. }
  11938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11939. {
  11940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11941. {
  11942. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11943. {
  11944. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11945. {
  11946. isMatchTransactiodId = TRUE;
  11947. break;
  11948. }
  11949. }
  11950. }
  11951. }
  11952. }
  11953. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11954. {
  11955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11956. {
  11957. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11958. }
  11959. else
  11960. {
  11961. tempIndex = SetProfileReq.ConnectorId -1;
  11962. }
  11963. for (int index = 0; index < CCS_QUANTITY; index++)
  11964. {
  11965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11966. {
  11967. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11968. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11969. {
  11970. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11971. {
  11972. isMatchTransactiodId = TRUE;
  11973. break;
  11974. }
  11975. }
  11976. }
  11977. }
  11978. }
  11979. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11980. {
  11981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11982. {
  11983. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11984. }
  11985. else
  11986. {
  11987. tempIndex = SetProfileReq.ConnectorId -1;
  11988. }
  11989. for (int index = 0; index < GB_QUANTITY; index++)
  11990. {
  11991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11992. {
  11993. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11994. {
  11995. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11996. {
  11997. isMatchTransactiodId = TRUE;
  11998. break;
  11999. }
  12000. }
  12001. }
  12002. }
  12003. }
  12004. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12005. {
  12006. tempIndex = SetProfileReq.ConnectorId -1;
  12007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12008. {
  12009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12010. {
  12011. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12012. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12013. {
  12014. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12015. {
  12016. isMatchTransactiodId = TRUE;
  12017. break;
  12018. }
  12019. }
  12020. }
  12021. }
  12022. }
  12023. else
  12024. {
  12025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12026. {
  12027. tempIndex = 2;
  12028. }
  12029. else
  12030. {
  12031. tempIndex = (SetProfileReq.ConnectorId -1);
  12032. }
  12033. for (int index = 0; index < AC_QUANTITY; index++)
  12034. {
  12035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12036. {
  12037. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12038. {
  12039. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12040. {
  12041. isMatchTransactiodId = TRUE;
  12042. break;
  12043. }
  12044. }
  12045. }
  12046. }
  12047. }
  12048. //check Transaction active
  12049. if(isMatchTransactiodId == FALSE)
  12050. {
  12051. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12052. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12053. goto end;
  12054. }
  12055. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12056. {
  12057. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12058. DEBUG_WARN("Connector id is over max gun number.\n");
  12059. goto end;
  12060. }
  12061. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12062. fp = fopen(filename, "r");
  12063. if (!fp)
  12064. {
  12065. DEBUG_INFO("%s does not create.\n", filename);
  12066. fp = fopen(filename, "w+");
  12067. }
  12068. else
  12069. {
  12070. //Check Charging Profile Count
  12071. while(fscanf(fp, "%s", dataLine) != EOF)
  12072. {
  12073. //DEBUG_INFO("word=%s\n",word);
  12074. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12075. {
  12076. profileQuantity += 1;
  12077. }
  12078. }
  12079. }
  12080. fclose(fp);
  12081. }
  12082. // Check ChargeProfileMaxStackLevel
  12083. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12084. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12085. {
  12086. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12087. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12088. goto end;
  12089. }
  12090. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12091. {
  12092. FILE *fp;
  12093. char dataLine[4096]={0};
  12094. char fnametemp[128]={0};
  12095. int tmpProfileQuantity;
  12096. //Check ChargePointMaxProfile.json exit
  12097. profileQuantity = 0;
  12098. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12099. {
  12100. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12101. //Check Charging Profile Count
  12102. tmpProfileQuantity = 0;
  12103. while(fscanf(fp, "%s", dataLine) != EOF)
  12104. {
  12105. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12106. {
  12107. profileQuantity += 1;
  12108. tmpProfileQuantity += 1;
  12109. }
  12110. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12111. }
  12112. fclose(fp);
  12113. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12114. }
  12115. //Check TxDefaultProfile_%d.json
  12116. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12117. {
  12118. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12119. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12120. if((access(fnametemp,F_OK))!=-1)
  12121. {
  12122. fp = fopen(fnametemp, "r");
  12123. //Check Charging Profile Count
  12124. tmpProfileQuantity = 0;
  12125. while(fscanf(fp, "%s", dataLine) != EOF)
  12126. {
  12127. //DEBUG_INFO("word=%s\n",word);
  12128. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12129. {
  12130. profileQuantity += 1;
  12131. tmpProfileQuantity += 1;
  12132. }
  12133. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12134. }
  12135. fclose(fp);
  12136. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12137. }
  12138. }
  12139. //Check TxProfile_%d.json
  12140. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12141. {
  12142. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12143. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12144. if((access(fnametemp,F_OK))!=-1)
  12145. {
  12146. fp = fopen(fnametemp, "r");
  12147. //Check Charging Profile Count
  12148. tmpProfileQuantity = 0;
  12149. while(fscanf(fp, "%s", dataLine) != EOF)
  12150. {
  12151. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12152. {
  12153. profileQuantity += 1;
  12154. tmpProfileQuantity += 1;
  12155. }
  12156. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12157. }
  12158. fclose(fp);
  12159. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12160. }
  12161. }
  12162. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12163. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12164. {
  12165. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12166. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12167. goto end;
  12168. }
  12169. }
  12170. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12171. //**********************************Write to File********************************************************/
  12172. {
  12173. FILE *infile;
  12174. FILE *outfile;
  12175. char dataLine[4096]={0};
  12176. char filename[128]={0};
  12177. int chkChar=0;
  12178. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12179. {
  12180. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12181. {
  12182. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12183. }
  12184. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12185. {
  12186. if(SetProfileReq.ConnectorId==0)
  12187. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12188. else
  12189. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12190. }
  12191. else
  12192. {
  12193. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12194. }
  12195. infile = fopen (filename, "r");
  12196. outfile = fopen (tempfile, "w");
  12197. chkChar = fgetc(infile);
  12198. rewind(infile);
  12199. if(chkChar == EOF)
  12200. {
  12201. // Profile is empty
  12202. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12203. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12204. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12205. fclose(infile);
  12206. fclose(outfile);
  12207. sprintf(rmFileCmd,"rm -f %s",filename);
  12208. system(rmFileCmd);
  12209. rename(tempfile, filename);
  12210. }
  12211. else
  12212. {
  12213. // Profile is not empty
  12214. int ChargingProfileAdded = FALSE;
  12215. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12216. {
  12217. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12218. json_object *tmpChargingProfile;
  12219. tmpChargingProfile = json_tokener_parse(dataLine);
  12220. if(!is_error(SetChargingProfile))
  12221. {
  12222. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12223. {
  12224. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12225. {
  12226. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12227. }
  12228. }
  12229. }
  12230. json_object_put(tmpChargingProfile);
  12231. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12232. {
  12233. if(ChargingProfileAdded == FALSE)
  12234. {
  12235. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12236. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12237. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12238. ChargingProfileAdded = TRUE;
  12239. }
  12240. }
  12241. else
  12242. {
  12243. fprintf(outfile,"%s\n",dataLine);
  12244. if(ChargingProfileAdded == FALSE)
  12245. {
  12246. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12247. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12248. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12249. ChargingProfileAdded = TRUE;
  12250. }
  12251. }
  12252. } // end of while loop
  12253. fclose(infile);
  12254. fclose(outfile);
  12255. sprintf(rmFileCmd,"rm -f %s",filename);
  12256. system(rmFileCmd);
  12257. rename(tempfile, filename);
  12258. }
  12259. }
  12260. sleep(1);
  12261. result = TRUE;
  12262. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12263. }
  12264. end:
  12265. json_object_put(SetChargingProfile);
  12266. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12267. {
  12268. if(SetProfileReq.ConnectorId == 0)
  12269. {
  12270. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12271. {
  12272. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12273. }
  12274. }
  12275. else
  12276. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12277. }
  12278. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12279. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12280. return result;
  12281. }
  12282. int handleTriggerMessageRequest(char *uuid, char *payload)
  12283. {
  12284. mtrace();
  12285. int result = FAIL;
  12286. int connectorIdIsNULL = FALSE;
  12287. int connectorIdInt =0;
  12288. char sstr[40]={0},sstrtemp[100]={ 0 };
  12289. char requestedMessagestr[40]={0};
  12290. char comfirmstr[20]={0};
  12291. int c = 0;
  12292. char *loc;
  12293. DEBUG_INFO("handleTriggerMessageRequest\n");
  12294. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12295. strcpy(sstrtemp, stringtrimspace(payload));
  12296. c = 0;
  12297. loc = strstr(sstrtemp, "requestedMessage");
  12298. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12299. {
  12300. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12301. c++;
  12302. }
  12303. sstr[c] = '\0';
  12304. strcpy(requestedMessagestr, sstr);
  12305. c = 0;
  12306. loc = strstr(sstrtemp, "connectorId");
  12307. if(loc == NULL)
  12308. {
  12309. connectorIdIsNULL = TRUE;
  12310. }
  12311. else
  12312. {
  12313. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12314. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12315. {
  12316. sstr[c] = loc[strlen("connectorId")+2+c];
  12317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12318. c++;
  12319. }
  12320. sstr[c] = '\0';
  12321. connectorIdInt = atoi(sstr);
  12322. }
  12323. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12324. {
  12325. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12326. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12327. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12328. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12329. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12330. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12331. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12332. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12333. {
  12334. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12335. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12336. return TRUE;
  12337. }
  12338. else
  12339. {
  12340. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12341. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12342. }
  12343. }
  12344. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12345. {
  12346. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12347. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12348. return TRUE;
  12349. }
  12350. //==========================
  12351. // Trigger message
  12352. //==========================
  12353. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12354. {
  12355. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12356. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12357. {
  12358. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12359. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12360. }
  12361. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12362. }
  12363. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12364. {
  12365. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12366. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12367. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12368. }
  12369. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12370. {
  12371. //sendBootNotificationRequest();
  12372. server_sign = FALSE;
  12373. }
  12374. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12375. {
  12376. refreshStartTimer(&clientTime.Heartbeat);
  12377. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12378. }
  12379. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12380. {
  12381. if(connectorIdIsNULL == FALSE)
  12382. {
  12383. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12384. {
  12385. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12386. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12387. }
  12388. }
  12389. else
  12390. {
  12391. for(int idx=0;idx< gunTotalNumber;idx++)
  12392. {
  12393. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12394. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12395. }
  12396. }
  12397. }
  12398. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12399. {
  12400. if(connectorIdIsNULL == FALSE)
  12401. {
  12402. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12403. {
  12404. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12405. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12406. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12407. }
  12408. }
  12409. else
  12410. {
  12411. for(int idx=0;idx< gunTotalNumber;idx++)
  12412. {
  12413. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12414. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12415. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12416. }
  12417. }
  12418. }
  12419. return result;
  12420. }
  12421. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12422. {
  12423. mtrace();
  12424. int result = FAIL;
  12425. int connectorIdInt =0;
  12426. char comfirmstr[20]={0};
  12427. int tempIndex = 0;
  12428. json_object *UnlockConnector;
  12429. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12430. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12431. UnlockConnector = json_tokener_parse(payload);
  12432. if(!is_error(UnlockConnector))
  12433. {
  12434. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12435. {
  12436. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12437. }
  12438. }
  12439. json_object_put(UnlockConnector);
  12440. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12441. if(gunTotalNumber == 0)
  12442. {
  12443. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12444. goto end;
  12445. }
  12446. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12447. {
  12448. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12449. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12450. goto end;
  12451. }
  12452. else
  12453. {
  12454. //check Transaction active
  12455. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12456. {
  12457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12458. {
  12459. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12460. }
  12461. else
  12462. {
  12463. tempIndex = connectorIdInt -1;
  12464. }
  12465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12466. {
  12467. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12468. {
  12469. //stop Transaction
  12470. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12471. }
  12472. }
  12473. }
  12474. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12475. {
  12476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12477. {
  12478. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12479. }
  12480. else
  12481. {
  12482. tempIndex = connectorIdInt -1;
  12483. }
  12484. for (int index = 0; index < CCS_QUANTITY; index++)
  12485. {
  12486. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12487. {
  12488. //stop Transaction
  12489. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12490. }
  12491. }
  12492. }
  12493. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12494. {
  12495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12496. {
  12497. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12498. }
  12499. else
  12500. {
  12501. tempIndex = connectorIdInt -1;
  12502. }
  12503. for (int index = 0; index < GB_QUANTITY; index++)
  12504. {
  12505. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12506. {
  12507. //stop Transaction
  12508. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12509. }
  12510. }
  12511. }
  12512. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12513. {
  12514. tempIndex = connectorIdInt -1;
  12515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12516. {
  12517. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12518. {
  12519. //stop Transaction
  12520. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12521. }
  12522. }
  12523. }
  12524. else
  12525. {
  12526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12527. {
  12528. tempIndex = 2;
  12529. }
  12530. else
  12531. {
  12532. tempIndex = connectorIdInt-1;
  12533. }
  12534. for (int index = 0; index < AC_QUANTITY; index++)
  12535. {
  12536. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12537. {
  12538. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12539. }
  12540. }
  12541. }
  12542. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12543. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12544. result = TRUE;
  12545. return result;
  12546. }
  12547. end:
  12548. //json_object_put(obj); --- remove temporally
  12549. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12550. return result;
  12551. }
  12552. static char UpdateFirmwarepayloadData[300]={0};
  12553. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12554. {
  12555. mtrace();
  12556. int result = FAIL;
  12557. pthread_t t;
  12558. sendUpdateFirmwareConfirmation(uuid);
  12559. memset(UpdateFirmwarepayloadData, 0, 300);
  12560. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12561. if(!interLock.isUpdateFirmwareGoing)
  12562. {
  12563. interLock.isUpdateFirmwareGoing = 1;
  12564. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12565. sleep(1);
  12566. }
  12567. else
  12568. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12569. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12570. return result;
  12571. }
  12572. void *UpdateFirmwareProcess(void *data)
  12573. {
  12574. pthread_detach(pthread_self());
  12575. mtrace();
  12576. int retriesInt =0, retryIntervalInt=0;
  12577. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12578. int port=0;
  12579. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12580. int isSuccess = 0;
  12581. char ftpbuf[1024];
  12582. char temp[1024];
  12583. char * pch;
  12584. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12585. json_object *UpdateFirmware;
  12586. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12587. if(!is_error(UpdateFirmware))
  12588. {
  12589. // Required data
  12590. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12591. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12592. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12593. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12594. // Optional data
  12595. if(json_object_object_get(UpdateFirmware, "retries"))
  12596. {
  12597. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12598. }
  12599. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12600. {
  12601. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12602. }
  12603. }
  12604. json_object_put(UpdateFirmware);
  12605. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12606. memset(path, 0, ARRAY_SIZE(path));
  12607. // Wait retrieveData
  12608. if(strlen(retrieveDatestr) > 10)
  12609. {
  12610. do
  12611. {
  12612. sleep(1);
  12613. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12614. }
  12615. // Ready to download
  12616. system("rm -f /mnt/*");
  12617. if(strncmp(locationstr,"http", 4) == 0)
  12618. {
  12619. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12620. sprintf(ftppath,"/%s", path);
  12621. DEBUG_INFO("locationstr: %s\n", locationstr);
  12622. DEBUG_INFO("protocol: %s\n",protocol);
  12623. DEBUG_INFO("host: %s\n",host);
  12624. DEBUG_INFO("path: %s\n",path);
  12625. DEBUG_INFO("ftppath: %s\n",ftppath);
  12626. int ftppathlen=strlen(ftppath);
  12627. int i=1;
  12628. char filenametemp[50];
  12629. while(i < ftppathlen)
  12630. {
  12631. int len=ftppathlen-i;
  12632. if(ftppath[len]== 47) // '/' ascll code: 47
  12633. {
  12634. DEBUG_INFO("compare '/' all right\n");
  12635. break;
  12636. }
  12637. i=i+1;
  12638. }
  12639. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12640. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12641. filenametemp[i+1] = 0;
  12642. do
  12643. {
  12644. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12645. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12646. sleep(1);
  12647. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12648. if(!isSuccess)
  12649. {
  12650. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12651. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12652. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12653. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12654. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12655. }
  12656. else
  12657. {
  12658. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12659. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12660. }
  12661. retriesInt--;
  12662. }while((isSuccess == 0)&&(retriesInt >= 0));
  12663. }
  12664. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12665. {
  12666. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12667. memset(temp, 0, ARRAY_SIZE(temp));
  12668. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12669. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12670. int ftppathlen=strlen(ftpbuf);
  12671. int i=1;
  12672. char filenametemp[50];
  12673. while(i < ftppathlen)
  12674. {
  12675. int len=ftppathlen-i;
  12676. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12677. {
  12678. DEBUG_INFO(" compare '/' all right\n");
  12679. break;
  12680. }
  12681. i=i+1;
  12682. }
  12683. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12684. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12685. filenametemp[i+1] = 0;
  12686. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12687. pch=strchr(temp,'@');
  12688. if(pch==NULL)
  12689. {
  12690. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12691. protocol, host, &port, path);
  12692. strcpy(user,"anonymous");
  12693. strcpy(password,"");
  12694. }
  12695. else
  12696. {
  12697. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12698. protocol, user, password, host, &port, path);
  12699. }
  12700. sscanf(host,"%[^/]%s",host1, path1);
  12701. sprintf(ftppath,"%s", path1);
  12702. //DEBUG_INFO("protocol =%s\n",protocol);
  12703. //DEBUG_INFO("user =%s\n",user);
  12704. //DEBUG_INFO("password =%s\n",password);
  12705. //DEBUG_INFO("host1 =%s\n",host1);
  12706. //DEBUG_INFO("port =%d\n",port);
  12707. //DEBUG_INFO("path1 =%s\n",path1);
  12708. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12709. //ftpFile(host, user, password, port, ftppath, fname);
  12710. //download firmware pthred
  12711. if(port == 0)
  12712. {
  12713. port = 21;
  12714. }
  12715. do
  12716. {
  12717. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12718. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12719. sleep(1);
  12720. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12721. if(!isSuccess)
  12722. {
  12723. //BulldogUtil.sleepMs(interval*1000);
  12724. DEBUG_INFO("Update firmware request and download file fail.\n");
  12725. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12726. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12727. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12728. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12730. }
  12731. else
  12732. {
  12733. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12734. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12735. }
  12736. retriesInt--;
  12737. }while((!isSuccess)&&(retriesInt >= 0));
  12738. }
  12739. else
  12740. {
  12741. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12742. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12743. sleep(1);
  12744. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12745. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12746. }
  12747. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12748. interLock.isUpdateFirmwareGoing = 0;
  12749. pthread_exit(NULL);
  12750. }
  12751. int handleCertificateSignedRequest(char *uuid, char *payload)
  12752. {
  12753. mtrace();
  12754. int result = PASS;
  12755. json_object *CertificateSigned;
  12756. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12757. CertificateSigned = json_tokener_parse(payload);
  12758. if(!is_error(CertificateSigned))
  12759. {
  12760. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12761. }
  12762. json_object_put(CertificateSigned);
  12763. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12764. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12765. fclose(fp);
  12766. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12767. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12768. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12769. sendCertificateSignedConfirmation(uuid);
  12770. return result;
  12771. }
  12772. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12773. {
  12774. mtrace();
  12775. int result = PASS;
  12776. json_object *DeleteCertificate;
  12777. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12778. DeleteCertificate = json_tokener_parse(payload);
  12779. if(!is_error(DeleteCertificate))
  12780. {
  12781. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12782. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12783. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12784. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12785. }
  12786. json_object_put(DeleteCertificate);
  12787. /*
  12788. * TODO: Delete certificateSigned process
  12789. */
  12790. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12791. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12792. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12793. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12794. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12795. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12796. sendDeleteCertificateConfirmation(uuid);
  12797. return result;
  12798. }
  12799. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12800. {
  12801. mtrace();
  12802. int result = PASS;
  12803. json_object *ExtendedTriggerMessage;
  12804. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12805. ExtendedTriggerMessage = json_tokener_parse(payload);
  12806. if(!is_error(ExtendedTriggerMessage))
  12807. {
  12808. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12809. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12810. {
  12811. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12812. }
  12813. else
  12814. {
  12815. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12816. }
  12817. }
  12818. json_object_put(ExtendedTriggerMessage);
  12819. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12820. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12821. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12822. {
  12823. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12824. }
  12825. else
  12826. {
  12827. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12828. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12829. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12830. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12831. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12832. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12833. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12834. {
  12835. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12836. }
  12837. else
  12838. {
  12839. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12840. }
  12841. }
  12842. sendExtendedTriggerMessageConfirmation(uuid);
  12843. //==========================
  12844. // Trigger message
  12845. //==========================
  12846. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12847. {
  12848. //sendBootNotificationRequest();
  12849. server_sign = FALSE;
  12850. }
  12851. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12852. {
  12853. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12854. }
  12855. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12856. {
  12857. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12858. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12859. {
  12860. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12861. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12862. }
  12863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12864. }
  12865. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12866. {
  12867. refreshStartTimer(&clientTime.Heartbeat);
  12868. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12869. }
  12870. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12871. {
  12872. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12873. {
  12874. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12875. }
  12876. else
  12877. {
  12878. for(int idx=0;idx< gunTotalNumber;idx++)
  12879. {
  12880. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12881. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12882. }
  12883. }
  12884. }
  12885. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12886. {
  12887. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12888. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12889. {
  12890. 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\" &");
  12891. }
  12892. }
  12893. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12894. {
  12895. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12896. {
  12897. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12898. }
  12899. else
  12900. {
  12901. for(int idx=0;idx< gunTotalNumber;idx++)
  12902. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12903. }
  12904. }
  12905. return result;
  12906. }
  12907. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12908. {
  12909. mtrace();
  12910. int result = PASS;
  12911. json_object *GetInstalledCertificateIds;
  12912. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12913. GetInstalledCertificateIds = json_tokener_parse(payload);
  12914. if(!is_error(GetInstalledCertificateIds))
  12915. {
  12916. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12917. }
  12918. json_object_put(GetInstalledCertificateIds);
  12919. /*
  12920. * TODO: Return installed certificate process
  12921. */
  12922. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12923. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12924. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12925. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12926. sendGetInstalledCertificateIdsConfirmation(uuid);
  12927. return result;
  12928. }
  12929. int handleGetLogRequest(char *uuid, char *payload)
  12930. {
  12931. mtrace();
  12932. int result = PASS;
  12933. json_object *GetLog;
  12934. DEBUG_INFO("handleGetLogRequest...\n");
  12935. GetLog = json_tokener_parse(payload);
  12936. if(!is_error(GetLog))
  12937. {
  12938. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12939. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12940. if(json_object_object_get(GetLog, "retries") != NULL)
  12941. {
  12942. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12943. }
  12944. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12945. {
  12946. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12947. }
  12948. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12949. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12950. {
  12951. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12952. }
  12953. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12954. {
  12955. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12956. }
  12957. }
  12958. json_object_put(GetLog);
  12959. /*
  12960. * TODO: Upload log process
  12961. */
  12962. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12963. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12964. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12965. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12966. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12967. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12968. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12969. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12970. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12971. sendGetLogConfirmation(uuid);
  12972. return result;
  12973. }
  12974. int handleInstallCertificateRequest(char *uuid, char *payload)
  12975. {
  12976. mtrace();
  12977. int result = PASS;
  12978. json_object *InstallCertificate;
  12979. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12980. InstallCertificate = json_tokener_parse(payload);
  12981. if(!is_error(InstallCertificate))
  12982. {
  12983. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12984. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12985. /*
  12986. * TODO: Install certificate process
  12987. */
  12988. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12989. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12990. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12991. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12992. sendInstallCertificateConfirmation(uuid);
  12993. }
  12994. json_object_put(InstallCertificate);
  12995. return result;
  12996. }
  12997. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12998. {
  12999. mtrace();
  13000. int result = PASS;
  13001. json_object *SignedUpdateFirmware;
  13002. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13003. SignedUpdateFirmware = json_tokener_parse(payload);
  13004. if(!is_error(SignedUpdateFirmware))
  13005. {
  13006. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13007. {
  13008. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13009. }
  13010. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13011. {
  13012. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13013. }
  13014. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13015. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13016. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13017. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13018. {
  13019. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13020. }
  13021. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13022. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13023. }
  13024. json_object_put(SignedUpdateFirmware);
  13025. /*
  13026. * TODO: Upgrade firmware process
  13027. */
  13028. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13029. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13030. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13031. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13032. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13033. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13034. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13035. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13036. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13037. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13038. sendInstallCertificateConfirmation(uuid);
  13039. return result;
  13040. }
  13041. int handleUnknownRequest(char *uuid, char *payload)
  13042. {
  13043. mtrace();
  13044. int result = PASS;
  13045. DEBUG_INFO("handleUnknownRequest...\n");
  13046. sendUnknownConfirmation(uuid);
  13047. result = PASS;
  13048. return result;
  13049. }
  13050. //==========================================
  13051. // Handle server response routine
  13052. //==========================================
  13053. void handleAuthorizeResponse(char *payload, int gun_index)
  13054. {
  13055. mtrace();
  13056. char expiryDatestr[30]={0};
  13057. char parentIdTagstr[20]={0};
  13058. char statusstr[20]={0};
  13059. int expiryDateISNULL=FALSE;
  13060. int parentIdTagISNULL=FALSE;
  13061. DEBUG_INFO("handleAuthorizeResponse...\n");
  13062. json_object *Authorize;
  13063. Authorize = json_tokener_parse(payload);
  13064. if(!is_error(Authorize))
  13065. {
  13066. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13067. {
  13068. // Required data
  13069. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13070. // Optional data
  13071. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13072. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13073. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13074. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13075. }
  13076. }
  13077. json_object_put(Authorize);
  13078. if(expiryDateISNULL == FALSE)
  13079. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13080. if(parentIdTagISNULL == FALSE)
  13081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13083. //Update idTag information to authorization cache if supproted
  13084. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13085. {
  13086. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13087. }
  13088. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13089. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13090. authorizeRetryTimes = 0;
  13091. }
  13092. void handleBootNotificationResponse(char *payload, int gun_index)
  13093. {
  13094. mtrace();
  13095. char statusStr[12]={0};
  13096. char currentTimeStr[30]={0};
  13097. int intervalInt = 0;
  13098. DEBUG_INFO("handleBootNotificationResponse...\n");
  13099. json_object *BootNotification;
  13100. BootNotification = json_tokener_parse(payload);
  13101. if(!is_error(BootNotification))
  13102. {
  13103. // Required data
  13104. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13105. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13106. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13107. }
  13108. json_object_put(BootNotification);
  13109. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13110. BootNotificationInterval = intervalInt;
  13111. //write back to ShmOCPP16Data->BootNotification
  13112. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13113. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13114. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13115. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13116. {
  13117. if((intervalInt == 0) || (intervalInt >= 10))
  13118. {
  13119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13120. HeartBeatWaitTime = intervalInt;
  13121. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13122. }
  13123. server_sign = TRUE;
  13124. server_pending =FALSE;
  13125. }
  13126. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13127. {
  13128. server_pending = TRUE;
  13129. }
  13130. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13131. srand(time(NULL));
  13132. refreshStartTimer(&clientTime.Heartbeat);
  13133. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13134. SetOcppConnStatus(TRUE);
  13135. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13136. }
  13137. void handleDataTransferResponse(char *payload, int gun_index)
  13138. {
  13139. char sstr[160]={0};//sstr[200]={ 0 };
  13140. int c = 0;
  13141. char *loc;
  13142. DEBUG_INFO("handleDataTransferResponse ...\n");
  13143. loc = strstr(payload, "status");
  13144. c = 0;
  13145. while (loc[3+strlen("status")+c] != '\"')
  13146. {
  13147. sstr[c] = loc[3+strlen("status")+c];
  13148. c++;
  13149. }
  13150. sstr[c] = '\0';
  13151. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  13152. }
  13153. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13154. {
  13155. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13156. //struct json_object *obj;
  13157. // obj = json_tokener_parse(payload);
  13158. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13159. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13160. //No fields are defined.
  13161. }
  13162. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13163. {
  13164. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13165. //struct json_object *obj;
  13166. // obj = json_tokener_parse(payload);
  13167. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13168. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13169. //No fields are defined.
  13170. }
  13171. void handleHeartbeatResponse(char *payload, int gun_index)
  13172. {
  13173. mtrace();
  13174. DEBUG_INFO("handleHeartbeatResponse...\n");
  13175. json_object *Heartbeat;
  13176. Heartbeat = json_tokener_parse(payload);
  13177. if(!is_error(Heartbeat))
  13178. {
  13179. // Required data
  13180. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13181. }
  13182. json_object_put(Heartbeat);
  13183. if(FirstHeartBeat == 0)
  13184. {
  13185. FirstHeartBeat = 1;
  13186. DEBUG_INFO("FirstHeartBeat \n");
  13187. }
  13188. HeartBeatWithNOResponse = 0;
  13189. refreshStartTimer(&clientTime.Heartbeat);
  13190. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13191. }
  13192. void handleMeterValuesResponse(char *payload, int gun_index)
  13193. {
  13194. mtrace();
  13195. DEBUG_INFO("handleMeterValuesResponse...\n");
  13196. isQueueSendable = 1;
  13197. }
  13198. void handleStartTransactionResponse(char *payload, int gun_index)
  13199. {
  13200. mtrace();
  13201. //int transactionIdInt = 0;
  13202. FILE *outfile;
  13203. char data[100]={0};
  13204. DEBUG_INFO("handleStartTransactionResponse...\n");
  13205. json_object *StartTransaction;
  13206. StartTransaction = json_tokener_parse(payload);
  13207. if(!is_error(StartTransaction))
  13208. {
  13209. // Required data
  13210. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13211. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13212. // Optional data
  13213. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13214. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13215. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13216. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13217. }
  13218. json_object_put(StartTransaction);
  13219. isQueueSendable = 1;
  13220. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13221. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13222. //-----------Start : write to the Queue TransactionId file -----------------//
  13223. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13224. {}
  13225. else
  13226. {
  13227. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13228. if(log == NULL)
  13229. {
  13230. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13231. return ;
  13232. }
  13233. else
  13234. {
  13235. fclose(log);
  13236. }
  13237. }
  13238. // open file for writing
  13239. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13240. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13241. {
  13242. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13243. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13244. fputs(data, outfile);
  13245. fclose (outfile);
  13246. }
  13247. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13248. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13249. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13250. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13251. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13252. }
  13253. void handleStatusNotificationResponse(char *payload, int gun_index)
  13254. {
  13255. mtrace();
  13256. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13257. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13258. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13259. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13260. }
  13261. void handleStopTransactionnResponse(char *payload, int gun_index)
  13262. {
  13263. mtrace();
  13264. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13265. json_object *StopTransaction;
  13266. StopTransaction = json_tokener_parse(payload);
  13267. if(!is_error(StopTransaction))
  13268. {
  13269. // Optional data
  13270. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13271. {
  13272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13273. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13275. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13276. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13277. }
  13278. }
  13279. json_object_put(StopTransaction);
  13280. isQueueSendable = 1;
  13281. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13282. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13283. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13284. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13285. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13286. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13287. }
  13288. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13289. {
  13290. mtrace();
  13291. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13292. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13293. }
  13294. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13295. {
  13296. mtrace();
  13297. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13298. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13299. }
  13300. void handleSignCertificateResponse(char *payload, int gun_index)
  13301. {
  13302. mtrace();
  13303. DEBUG_INFO("handleSignCertificateResponse...\n");
  13304. json_object *SignCertificate;
  13305. SignCertificate = json_tokener_parse(payload);
  13306. if(!is_error(SignCertificate))
  13307. {
  13308. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13309. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13310. }
  13311. json_object_put(SignCertificate);
  13312. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13313. }
  13314. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13315. {
  13316. mtrace();
  13317. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13318. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13319. }
  13320. //==========================================
  13321. // Handle Error routine
  13322. //==========================================
  13323. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13324. {
  13325. mtrace();
  13326. #ifdef SystemLogMessage
  13327. DEBUG_INFO("errorCode: %s\n", errorCode);
  13328. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13329. DEBUG_INFO("errorDetails: %s\n", payload);
  13330. #endif
  13331. }
  13332. //===============================================
  13333. // Common routine
  13334. //===============================================
  13335. int initialConfigurationTable(void)
  13336. {
  13337. //clock_t start_t, end_t, total_t;
  13338. FILE *fp;
  13339. FILE *outfile;
  13340. char str[512]={0};
  13341. char sstr[256]={0};
  13342. int c = 0;
  13343. char *loc;
  13344. int confVersion = 11;
  13345. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13346. //start_t = clock();
  13347. //printf("Starting of the program, start_t = %ld\n", start_t);
  13348. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13349. // Check configuration file size is correct
  13350. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13351. {
  13352. struct stat st;
  13353. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13354. if(st.st_size < 3100)
  13355. {
  13356. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13357. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13358. }
  13359. }
  13360. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13361. {
  13362. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13363. if(outfile == NULL)
  13364. {
  13365. DEBUG_INFO("Error opening file\n");
  13366. return FALSE;
  13367. }
  13368. /*Core Profile*/
  13369. //AllowOfflineTxForUnknownId
  13370. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13374. //AuthorizationCacheEnabled
  13375. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13379. //AuthorizeRemoteTxRequests
  13380. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13384. //BlinkRepeat
  13385. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13389. //ClockAlignedDataInterval
  13390. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13394. //ConnectionTimeOut
  13395. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13399. //GetConfigurationMaxKeys
  13400. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13404. // HeartbeatInterval
  13405. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13409. // LightIntensity
  13410. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13414. // LocalAuthorizeOffline
  13415. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13419. // LocalPreAuthorize
  13420. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13424. // MaxEnergyOnInvalidId
  13425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13429. // MeterValuesAlignedData
  13430. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13433. 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" );
  13434. else
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13437. // MeterValuesAlignedDataMaxLength
  13438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13442. else
  13443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13445. // MeterValuesSampledData
  13446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13449. 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" );
  13450. else
  13451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13453. // MeterValuesSampledDataMaxLength
  13454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13458. else
  13459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13461. // MeterValueSampleInterval
  13462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13466. // MinimumStatusDuration
  13467. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13470. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13472. // NumberOfConnectors
  13473. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13476. {
  13477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13478. }
  13479. else
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13482. }
  13483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13484. // ResetRetries
  13485. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13489. // ConnectorPhaseRotation
  13490. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13494. // ConnectorPhaseRotationMaxLength
  13495. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13499. // StopTransactionOnEVSideDisconnect
  13500. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13504. // StopTransactionOnInvalidId
  13505. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13509. // StopTxnAlignedData
  13510. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13514. // StopTxnAlignedDataMaxLength
  13515. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13519. // StopTxnSampledData
  13520. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13524. else
  13525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13527. // StopTxnSampledDataMaxLength
  13528. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13531. {
  13532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13533. }
  13534. else
  13535. {
  13536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13537. }
  13538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13539. // SupportedFeatureProfiles
  13540. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13544. // SupportedFeatureProfilesMaxLength
  13545. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13549. // TransactionMessageAttempts
  13550. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13553. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13555. // TransactionMessageRetryInterval
  13556. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13559. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13561. // UnlockConnectorOnEVSideDisconnect
  13562. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13566. // WebSocketPingInterval
  13567. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13571. // QueueOffLineMeterValues
  13572. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13576. // AuthorizationKey
  13577. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13581. // SecurityProfile
  13582. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13586. // DefaultPrice
  13587. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13591. // CustomDisplayCostAndPrice
  13592. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13596. // CustomIdleFeeAfterStop
  13597. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13601. // TimeOffset
  13602. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13606. // NextTimeOffsetTransitionDateTime
  13607. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13611. // TimeOffsetNextTransition
  13612. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13616. // SystemUptimeSec
  13617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13621. // FreeVend
  13622. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13626. // OcppServer
  13627. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13629. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13631. // MaintainServer
  13632. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13634. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13636. // Configuration Version
  13637. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13641. //* Local Auth List Management Profile*/
  13642. #if 0
  13643. //For OCTT Test Case
  13644. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13647. #endif
  13648. #if 1
  13649. //LocalAuthListEnabled
  13650. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13654. #endif
  13655. //LocalAuthListMaxLength
  13656. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13660. //SendLocalListMaxLength
  13661. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13665. //ReserveConnectorZeroSupported
  13666. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13670. //* Smart Charging Profile */
  13671. //ChargeProfileMaxStackLevel
  13672. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13676. // ChargingScheduleAllowedChargingRateUnit
  13677. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13681. // ChargingScheduleMaxPeriods
  13682. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13686. // ConnectorSwitch3to1PhaseSupported
  13687. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13691. // MaxChargingProfilesInstalled
  13692. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13696. fclose(outfile);
  13697. }
  13698. else
  13699. {
  13700. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13701. char keystr[60]={0};
  13702. char readonlystr[10]={0};
  13703. char valuestr[256]={0};
  13704. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13705. if(fp == NULL) {
  13706. DEBUG_INFO("Error opening file");
  13707. return FALSE;
  13708. }
  13709. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13710. {
  13711. //DEBUG_INFO("Get Configuration \n");
  13712. if(strlen(str) > 0)
  13713. {
  13714. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13715. //*************************key*********************************/
  13716. if(strstr(str, "key") != NULL)
  13717. {
  13718. loc = strstr(str, "key");
  13719. c = 0;
  13720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13721. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13722. {
  13723. sstr[c] = loc[strlen("key")+3+c];
  13724. c++;
  13725. }
  13726. sstr[c] = '\0';
  13727. strcpy(keystr,sstr);
  13728. }
  13729. //*************************readonly*********************************/
  13730. if(strstr(str, "readonly") != NULL)
  13731. {
  13732. loc = strstr(str, "readonly");
  13733. c = 0;
  13734. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13735. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13736. {
  13737. sstr[c] = loc[strlen("readonly")+2+c];
  13738. c++;
  13739. }
  13740. sstr[c] = '\0';
  13741. strcpy(readonlystr,sstr);
  13742. }
  13743. //*************************value*********************************/
  13744. if(strstr(str, "value") != NULL)
  13745. {
  13746. loc = strstr(str, "value");
  13747. c = 0;
  13748. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13749. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13750. {
  13751. sstr[c] = loc[strlen("value")+3+c];
  13752. c++;
  13753. }
  13754. sstr[c] = '\0';
  13755. strcpy(valuestr,sstr);
  13756. }
  13757. // DEBUG_INFO("keystr=%s\n",keystr);
  13758. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13759. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13760. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13761. {
  13762. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13763. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13765. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13766. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13767. }
  13768. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13769. {
  13770. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13773. }
  13774. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13775. {
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13778. }
  13779. if(strcmp(keystr, "BlinkRepeat") == 0)
  13780. {
  13781. //Charger.BlinkRepeat = Integer.parseInt(value);
  13782. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13784. }
  13785. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13786. {
  13787. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13789. }
  13790. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13791. {
  13792. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13794. }
  13795. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13796. {
  13797. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13799. }
  13800. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13801. {
  13802. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13804. HeartBeatWaitTime = atoi(valuestr);
  13805. }
  13806. if(strcmp(keystr, "LightIntensity") == 0)
  13807. {
  13808. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13810. }
  13811. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13812. {
  13813. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13815. }
  13816. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13817. {
  13818. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13820. }
  13821. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13822. {
  13823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13825. }
  13826. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13827. {
  13828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13830. }
  13831. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13832. {
  13833. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13835. }
  13836. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13837. {
  13838. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13840. }
  13841. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13842. {
  13843. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13845. }
  13846. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13847. {
  13848. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13850. }
  13851. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13852. {
  13853. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13855. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13856. }
  13857. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13858. {
  13859. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13861. }
  13862. if(strcmp(keystr, "ResetRetries") == 0)
  13863. {
  13864. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13866. }
  13867. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13868. {
  13869. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13871. }
  13872. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13873. {
  13874. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13876. }
  13877. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13878. {
  13879. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13881. }
  13882. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13883. {
  13884. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13886. }
  13887. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13888. {
  13889. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13891. }
  13892. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13893. {
  13894. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13896. }
  13897. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13898. {
  13899. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13901. }
  13902. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13903. {
  13904. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13906. }
  13907. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13908. {
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13911. }
  13912. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13913. {
  13914. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13916. }
  13917. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13918. {
  13919. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13921. TransactionMessageAttemptsValue = atoi(valuestr);
  13922. }
  13923. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13924. {
  13925. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13927. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13928. }
  13929. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13930. {
  13931. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13933. }
  13934. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13935. {
  13936. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13938. }
  13939. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13940. {
  13941. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13943. }
  13944. if(strcmp(keystr, "AuthorizationKey") == 0)
  13945. {
  13946. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13947. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13949. }
  13950. if(strcmp(keystr, "SecurityProfile") == 0)
  13951. {
  13952. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13954. }
  13955. if(strcmp(keystr, "DefaultPrice") == 0)
  13956. {
  13957. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13959. }
  13960. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13961. {
  13962. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13964. }
  13965. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13966. {
  13967. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13969. }
  13970. if(strcmp(keystr, "TimeOffset") == 0)
  13971. {
  13972. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13974. }
  13975. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13976. {
  13977. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13979. }
  13980. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13981. {
  13982. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13984. }
  13985. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13986. {
  13987. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13989. }
  13990. if(strcmp(keystr, "FreeVend") == 0)
  13991. {
  13992. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13994. }
  13995. if(strcmp(keystr, "OcppServer") == 0)
  13996. {
  13997. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13998. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13999. }
  14000. if(strcmp(keystr, "MaintainServer") == 0)
  14001. {
  14002. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14003. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14004. }
  14005. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14006. {
  14007. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14009. }
  14010. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14011. {
  14012. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14014. }
  14015. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14016. {
  14017. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14019. }
  14020. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14021. {
  14022. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14024. }
  14025. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14026. {
  14027. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14029. }
  14030. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14031. {
  14032. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14034. }
  14035. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14036. {
  14037. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14039. }
  14040. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14041. {
  14042. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14044. }
  14045. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14046. {
  14047. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14049. }
  14050. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14051. {
  14052. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14054. }
  14055. }
  14056. }
  14057. fclose(fp);
  14058. }
  14059. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14060. {
  14061. return PASS;
  14062. }
  14063. else
  14064. {
  14065. return FAIL;
  14066. }
  14067. }
  14068. void StoreConfigurationTable(void)
  14069. {
  14070. FILE *outfile;
  14071. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14072. if(outfile == NULL)
  14073. {
  14074. DEBUG_INFO("Error opening file");
  14075. return ;
  14076. }
  14077. /*Core Profile*/
  14078. //AllowOfflineTxForUnknownId
  14079. /*
  14080. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14081. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14084. */
  14085. //DEBUG_INFO("data=%s\n",data);
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14087. //AuthorizationCacheEnabled
  14088. /*
  14089. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14094. //AuthorizeRemoteTxRequests
  14095. /*
  14096. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14101. //BlinkRepeat
  14102. /*
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14108. //ClockAlignedDataInterval
  14109. /*
  14110. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14115. //ConnectionTimeOut
  14116. /*
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14122. //GetConfigurationMaxKeys
  14123. /*
  14124. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14129. // HeartbeatInterval
  14130. /*
  14131. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14136. // LightIntensity
  14137. /*
  14138. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14143. // LocalAuthorizeOffline
  14144. /*
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14150. // LocalPreAuthorize
  14151. /*
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14155. */
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14157. // MaxEnergyOnInvalidId
  14158. /*
  14159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14162. */
  14163. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14165. // MeterValuesAlignedData
  14166. /*
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14170. */
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14172. // MeterValuesAlignedDataMaxLength
  14173. /*
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14179. // MeterValuesSampledData
  14180. /*
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14184. */
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14186. // MeterValuesSampledDataMaxLength
  14187. /*
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14191. */
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14193. // MeterValueSampleInterval
  14194. /*
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14198. */
  14199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14200. // MinimumStatusDuration
  14201. /*
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14205. */
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14207. // NumberOfConnectors
  14208. /*
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14212. {
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14214. }
  14215. else
  14216. {
  14217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14218. }
  14219. */
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14221. // ResetRetries
  14222. /*
  14223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14226. */
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14228. // ConnectorPhaseRotation
  14229. /*
  14230. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14233. */
  14234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14235. // ConnectorPhaseRotationMaxLength
  14236. /*
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14240. */
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14242. // StopTransactionOnEVSideDisconnect
  14243. /*
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14247. */
  14248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14249. // StopTransactionOnInvalidId
  14250. /*
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14254. */
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14256. // StopTxnAlignedData
  14257. /*
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14261. */
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14263. // StopTxnAlignedDataMaxLength
  14264. /*
  14265. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14268. */
  14269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14270. // StopTxnSampledData
  14271. /*
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14275. */
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14277. // StopTxnSampledDataMaxLength
  14278. /*
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14282. */
  14283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14284. // SupportedFeatureProfiles
  14285. /*
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14289. */
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14291. // SupportedFeatureProfilesMaxLength
  14292. /*
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14296. */
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14298. // TransactionMessageAttempts
  14299. /*
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14303. */
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14305. // TransactionMessageRetryInterval
  14306. /*
  14307. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14310. */
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14312. // UnlockConnectorOnEVSideDisconnect
  14313. /*
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14317. */
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14319. // WebSocketPingInterval
  14320. /*
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14324. */
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14326. // QueueOffLineMeterValues
  14327. /*
  14328. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14331. */
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14333. // AuthorizationKey
  14334. /*
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14338. */
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14340. // SecurityProfile
  14341. /*
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14345. */
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14347. // DefaultPrice
  14348. /*
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14352. */
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14354. // CustomDisplayCostAndPrice
  14355. /*
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14359. */
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14361. // CustomIdleFeeAfterStop
  14362. /*
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14366. */
  14367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14368. // TimeOffset
  14369. /*
  14370. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14373. */
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14375. // NextTimeOffsetTransitionDateTime
  14376. /*
  14377. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14380. */
  14381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14382. // TimeOffsetNextTransition
  14383. /*
  14384. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14387. */
  14388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14389. // SystemUptimeSec
  14390. /*
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14394. */
  14395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14396. // FreeVend
  14397. /*
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14401. */
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14403. // OcppServer
  14404. /*
  14405. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14408. */
  14409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14410. // MaintainServer
  14411. /*
  14412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14415. */
  14416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14417. // ConfigurationVersion
  14418. /*
  14419. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14422. */
  14423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14424. //* Local Auth List Management Profile*/
  14425. //LocalAuthListEnabled
  14426. /*
  14427. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14430. */
  14431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14432. //LocalAuthListMaxLength
  14433. /*
  14434. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14437. */
  14438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14439. //SendLocalListMaxLength
  14440. /*
  14441. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14444. */
  14445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14446. //ReserveConnectorZeroSupported
  14447. /*
  14448. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14451. */
  14452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14453. //* Smart Charging Profile */
  14454. //ChargeProfileMaxStackLevel
  14455. /*
  14456. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14459. */
  14460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14461. // ChargingScheduleAllowedChargingRateUnit
  14462. /*
  14463. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14466. */
  14467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14468. // ChargingScheduleMaxPeriods
  14469. /*
  14470. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14473. */
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14475. // ConnectorSwitch3to1PhaseSupported
  14476. /*
  14477. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14480. */
  14481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14482. // MaxChargingProfilesInstalled
  14483. /*
  14484. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14487. */
  14488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14489. fclose(outfile);
  14490. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14491. }
  14492. void getKeyValue(char *keyReq)
  14493. {
  14494. int isEmpty = FALSE;
  14495. int isKnowKey = FALSE;
  14496. DEBUG_INFO("keyReq = %s\n", keyReq);
  14497. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14498. isEmpty = TRUE;
  14499. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14500. {
  14501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14504. {
  14505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14506. }
  14507. else
  14508. {
  14509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14510. }
  14511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14512. isKnowKey = TRUE;
  14513. }
  14514. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14515. {
  14516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14519. {
  14520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14521. }
  14522. else
  14523. {
  14524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14525. }
  14526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14527. isKnowKey = TRUE;
  14528. }
  14529. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14530. {
  14531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14534. {
  14535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14536. }
  14537. else
  14538. {
  14539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14540. }
  14541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14542. isKnowKey = TRUE;
  14543. }
  14544. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14545. {
  14546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14549. {
  14550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14551. }
  14552. else
  14553. {
  14554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14555. }
  14556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14557. isKnowKey = TRUE;
  14558. }
  14559. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14560. {
  14561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14564. {
  14565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14566. }
  14567. else
  14568. {
  14569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14570. }
  14571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14572. isKnowKey = TRUE;
  14573. }
  14574. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14575. {
  14576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14579. {
  14580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14581. }
  14582. else
  14583. {
  14584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14585. }
  14586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14587. isKnowKey = TRUE;
  14588. }
  14589. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14590. {
  14591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14594. {
  14595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14596. }
  14597. else
  14598. {
  14599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14600. }
  14601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14602. isKnowKey = TRUE;
  14603. }
  14604. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14605. {
  14606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14609. {
  14610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14611. }
  14612. else
  14613. {
  14614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14615. }
  14616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14617. isKnowKey = TRUE;
  14618. }
  14619. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14620. {
  14621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14624. {
  14625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14626. }
  14627. else
  14628. {
  14629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14630. }
  14631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14632. isKnowKey = TRUE;
  14633. }
  14634. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14635. {
  14636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14639. {
  14640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14641. }
  14642. else
  14643. {
  14644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14645. }
  14646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14647. isKnowKey = TRUE;
  14648. }
  14649. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14650. {
  14651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14654. {
  14655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14656. }
  14657. else
  14658. {
  14659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14660. }
  14661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14662. isKnowKey = TRUE;
  14663. }
  14664. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14665. {
  14666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14669. {
  14670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14671. }
  14672. else
  14673. {
  14674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14675. }
  14676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14677. isKnowKey = TRUE;
  14678. }
  14679. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14680. {
  14681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14684. {
  14685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14686. }
  14687. else
  14688. {
  14689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14690. }
  14691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14692. isKnowKey = TRUE;
  14693. }
  14694. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14695. {
  14696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14699. {
  14700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14701. }
  14702. else
  14703. {
  14704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14705. }
  14706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14707. isKnowKey = TRUE;
  14708. }
  14709. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14710. {
  14711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14714. {
  14715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14716. }
  14717. else
  14718. {
  14719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14720. }
  14721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14722. isKnowKey = TRUE;
  14723. }
  14724. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14725. {
  14726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14729. {
  14730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14731. }
  14732. else
  14733. {
  14734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14735. }
  14736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14737. isKnowKey = TRUE;
  14738. }
  14739. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14740. {
  14741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14744. {
  14745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14746. }
  14747. else
  14748. {
  14749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14750. }
  14751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14752. isKnowKey = TRUE;
  14753. }
  14754. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14755. {
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14759. {
  14760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14761. }
  14762. else
  14763. {
  14764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14765. }
  14766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14767. isKnowKey = TRUE;
  14768. }
  14769. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14770. {
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14774. {
  14775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14776. }
  14777. else
  14778. {
  14779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14780. }
  14781. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14783. isKnowKey = TRUE;
  14784. }
  14785. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14786. {
  14787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14790. {
  14791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14792. }
  14793. else
  14794. {
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14796. }
  14797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14798. isKnowKey = TRUE;
  14799. }
  14800. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14801. {
  14802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14805. {
  14806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14807. }
  14808. else
  14809. {
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14811. }
  14812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14813. isKnowKey = TRUE;
  14814. }
  14815. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14816. {
  14817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14820. {
  14821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14822. }
  14823. else
  14824. {
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14826. }
  14827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14828. isKnowKey = TRUE;
  14829. }
  14830. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14831. {
  14832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14835. {
  14836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14837. }
  14838. else
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14841. }
  14842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14843. isKnowKey = TRUE;
  14844. }
  14845. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14846. {
  14847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14850. {
  14851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14852. }
  14853. else
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14856. }
  14857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14858. isKnowKey = TRUE;
  14859. }
  14860. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14861. {
  14862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14865. {
  14866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14867. }
  14868. else
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14871. }
  14872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14873. isKnowKey = TRUE;
  14874. }
  14875. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14876. {
  14877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14882. }
  14883. else
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14886. }
  14887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14888. isKnowKey = TRUE;
  14889. }
  14890. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14891. {
  14892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14897. }
  14898. else
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14901. }
  14902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14903. isKnowKey = TRUE;
  14904. }
  14905. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14906. {
  14907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14910. {
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14912. }
  14913. else
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14916. }
  14917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14918. isKnowKey = TRUE;
  14919. }
  14920. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14921. {
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14927. }
  14928. else
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14931. }
  14932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14933. isKnowKey = TRUE;
  14934. }
  14935. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14936. {
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14942. }
  14943. else
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14946. }
  14947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14948. isKnowKey = TRUE;
  14949. }
  14950. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14951. {
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14957. }
  14958. else
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14961. }
  14962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14963. isKnowKey = TRUE;
  14964. }
  14965. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14966. {
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14970. {
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14972. }
  14973. else
  14974. {
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14976. }
  14977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14978. isKnowKey = TRUE;
  14979. }
  14980. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14981. {
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14985. {
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14987. }
  14988. else
  14989. {
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14991. }
  14992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14993. isKnowKey = TRUE;
  14994. }
  14995. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14996. {
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15000. {
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15002. }
  15003. else
  15004. {
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15006. }
  15007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15008. isKnowKey = TRUE;
  15009. }
  15010. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15011. {
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15017. }
  15018. else
  15019. {
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15021. }
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15023. isKnowKey = TRUE;
  15024. }
  15025. /*
  15026. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15027. {
  15028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15031. {
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15033. }
  15034. else
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15037. }
  15038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15039. isKnowKey = TRUE;
  15040. }*/
  15041. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15042. {
  15043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15048. }
  15049. else
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15052. }
  15053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15054. isKnowKey = TRUE;
  15055. }
  15056. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15057. {
  15058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15063. }
  15064. else
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15067. }
  15068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15069. isKnowKey = TRUE;
  15070. }
  15071. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15072. {
  15073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15076. {
  15077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15078. }
  15079. else
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15082. }
  15083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15084. isKnowKey = TRUE;
  15085. }
  15086. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15087. {
  15088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15091. {
  15092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15093. }
  15094. else
  15095. {
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15097. }
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15099. isKnowKey = TRUE;
  15100. }
  15101. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15102. {
  15103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15106. {
  15107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15108. }
  15109. else
  15110. {
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15112. }
  15113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15114. isKnowKey = TRUE;
  15115. }
  15116. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15117. {
  15118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15121. {
  15122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15123. }
  15124. else
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15127. }
  15128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15129. isKnowKey = TRUE;
  15130. }
  15131. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15132. {
  15133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15136. {
  15137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15138. }
  15139. else
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15142. }
  15143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15144. isKnowKey = TRUE;
  15145. }
  15146. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15147. {
  15148. struct sysinfo s_info;
  15149. int error = sysinfo(&s_info);
  15150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15153. {
  15154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15155. }
  15156. else
  15157. {
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15159. }
  15160. if(error != 0)
  15161. {
  15162. DEBUG_WARN("System uptime get error: %d\n", error);
  15163. }
  15164. else
  15165. {
  15166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15167. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15168. }
  15169. isKnowKey = TRUE;
  15170. }
  15171. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15172. {
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15176. {
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15178. }
  15179. else
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15182. }
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15199. isKnowKey = TRUE;
  15200. }
  15201. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15202. {
  15203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15206. {
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15208. }
  15209. else
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15212. }
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15214. isKnowKey = TRUE;
  15215. }
  15216. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. #if 1
  15232. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15233. {
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15236. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15237. {
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15239. }
  15240. else
  15241. {
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15243. }
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15245. isKnowKey = TRUE;
  15246. }
  15247. #endif
  15248. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15249. {
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15252. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15253. {
  15254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15255. }
  15256. else
  15257. {
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15259. }
  15260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15261. isKnowKey = TRUE;
  15262. }
  15263. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15264. {
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15267. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15268. {
  15269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15270. }
  15271. else
  15272. {
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15274. }
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15276. isKnowKey = TRUE;
  15277. }
  15278. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15279. {
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15282. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15283. {
  15284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15285. }
  15286. else
  15287. {
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15289. }
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15291. isKnowKey = TRUE;
  15292. }
  15293. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15294. {
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15297. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15298. {
  15299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15300. }
  15301. else
  15302. {
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15304. }
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15306. isKnowKey = TRUE;
  15307. }
  15308. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15309. {
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15312. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15313. {
  15314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15315. }
  15316. else
  15317. {
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15319. }
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15321. isKnowKey = TRUE;
  15322. }
  15323. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15324. {
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15327. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15328. {
  15329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15330. }
  15331. else
  15332. {
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15334. }
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15336. isKnowKey = TRUE;
  15337. }
  15338. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15339. {
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15342. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15343. {
  15344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15345. }
  15346. else
  15347. {
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15349. }
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15351. isKnowKey = TRUE;
  15352. }
  15353. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15354. {
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15357. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15358. {
  15359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15360. }
  15361. else
  15362. {
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15364. }
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15366. isKnowKey = TRUE;
  15367. }
  15368. //=========================================================
  15369. if(!isEmpty && !isKnowKey)
  15370. {
  15371. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15372. strcpy(unknownkey[UnknownKeynum], keyReq);
  15373. UnknownKeynum = UnknownKeynum + 1;
  15374. }
  15375. }
  15376. void processUnkownKey(void)
  15377. {
  15378. DEBUG_INFO("processUnkownKey...\n");
  15379. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15380. for(int index=0; index < UnknownKeynum; index++)
  15381. {
  15382. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15383. {
  15384. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15385. }
  15386. }
  15387. }
  15388. int setKeyValue(char *key, char *value)
  15389. {
  15390. int isSuccess = NotSupported;
  15391. int check_ascii=0;
  15392. char str[501]={0};
  15393. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15394. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15395. {
  15396. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15398. {
  15399. strcpy(str, (const char*)value);
  15400. for(int i = 0; str[i]; i++){
  15401. str[i] = tolower(str[i]);
  15402. }
  15403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15404. isSuccess = ConfigurationStatus_Accepted;
  15405. }
  15406. else
  15407. {
  15408. isSuccess = ConfigurationStatus_Rejected;
  15409. }
  15410. }
  15411. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15412. {
  15413. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15415. {
  15416. strcpy(str, (const char*)value);
  15417. for(int i = 0; str[i]; i++){
  15418. str[i] = tolower(str[i]);
  15419. }
  15420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15421. isSuccess = ConfigurationStatus_Accepted;
  15422. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15423. }
  15424. else
  15425. {
  15426. isSuccess = ConfigurationStatus_Rejected;
  15427. }
  15428. }
  15429. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15430. {
  15431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15432. {
  15433. strcpy(str, (const char*)value);
  15434. for(int i = 0; str[i]; i++)
  15435. {
  15436. str[i] = tolower(str[i]);
  15437. }
  15438. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15440. isSuccess = ConfigurationStatus_Accepted;
  15441. }
  15442. else
  15443. {
  15444. isSuccess = ConfigurationStatus_Rejected;
  15445. }
  15446. }
  15447. if(strcmp(key, "BlinkRepeat") == 0)
  15448. {
  15449. //Charger.BlinkRepeat = Integer.parseInt(value);
  15450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15451. {
  15452. check_ascii = value[0];
  15453. if( (check_ascii < 48) || (check_ascii > 57) )
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. else
  15458. {
  15459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15460. isSuccess = ConfigurationStatus_Accepted;
  15461. }
  15462. }
  15463. else
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. }
  15468. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15469. {
  15470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15471. {
  15472. check_ascii = value[0];
  15473. if( (check_ascii < 48) || (check_ascii > 57) )
  15474. {
  15475. isSuccess = ConfigurationStatus_Rejected;
  15476. }
  15477. else
  15478. {
  15479. if((atoi(value) == 0) || (atoi(value) >= 5))
  15480. {
  15481. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15483. isSuccess = ConfigurationStatus_Accepted;
  15484. }
  15485. else
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. }
  15489. else
  15490. {
  15491. isSuccess = ConfigurationStatus_Rejected;
  15492. }
  15493. }
  15494. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15495. {
  15496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15497. {
  15498. check_ascii = value[0];
  15499. if( (check_ascii < 48) || (check_ascii > 57) )
  15500. {
  15501. isSuccess = ConfigurationStatus_Rejected;
  15502. }
  15503. else
  15504. {
  15505. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15507. isSuccess = ConfigurationStatus_Accepted;
  15508. }
  15509. }
  15510. else
  15511. {
  15512. isSuccess = ConfigurationStatus_Rejected;
  15513. }
  15514. }
  15515. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15516. {
  15517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15518. {
  15519. check_ascii = value[0];
  15520. if( (check_ascii < 48) || (check_ascii > 57) )
  15521. {
  15522. isSuccess = ConfigurationStatus_Rejected;
  15523. }
  15524. else
  15525. {
  15526. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15528. isSuccess = ConfigurationStatus_Accepted;
  15529. }
  15530. }
  15531. else
  15532. {
  15533. isSuccess = ConfigurationStatus_Rejected;
  15534. }
  15535. }
  15536. if(strcmp(key, "HeartbeatInterval") == 0)
  15537. {
  15538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15539. {
  15540. check_ascii = value[0];
  15541. if( (check_ascii < 48) || (check_ascii > 57) )
  15542. {
  15543. isSuccess = ConfigurationStatus_Rejected;
  15544. }
  15545. else
  15546. {
  15547. if((atoi(value) == 0) || (atoi(value) >= 10))
  15548. {
  15549. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15551. HeartBeatWaitTime = atoi(value);
  15552. isSuccess = ConfigurationStatus_Accepted;
  15553. }
  15554. else
  15555. {
  15556. isSuccess = ConfigurationStatus_Rejected;
  15557. }
  15558. }
  15559. }
  15560. else
  15561. {
  15562. isSuccess = ConfigurationStatus_Rejected;
  15563. }
  15564. }
  15565. if(strcmp(key, "LightIntensity") == 0)
  15566. {
  15567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15568. {
  15569. check_ascii = value[0];
  15570. if( (check_ascii < 48) || (check_ascii > 57) )
  15571. {
  15572. isSuccess = ConfigurationStatus_Rejected;
  15573. }
  15574. else
  15575. {
  15576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15577. isSuccess = ConfigurationStatus_Accepted;
  15578. }
  15579. }
  15580. else
  15581. {
  15582. isSuccess = ConfigurationStatus_Rejected;
  15583. }
  15584. }
  15585. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15586. {
  15587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15588. {
  15589. strcpy(str, (const char*)value);
  15590. for(int i = 0; str[i]; i++)
  15591. {
  15592. str[i] = tolower(str[i]);
  15593. }
  15594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15595. isSuccess = ConfigurationStatus_Accepted;
  15596. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15597. }
  15598. else
  15599. {
  15600. isSuccess = ConfigurationStatus_Rejected;
  15601. }
  15602. }
  15603. if(strcmp(key, "LocalPreAuthorize") == 0)
  15604. {
  15605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15606. {
  15607. strcpy(str, (const char*)value);
  15608. for(int i = 0; str[i]; i++)
  15609. {
  15610. str[i] = tolower(str[i]);
  15611. }
  15612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15613. isSuccess = ConfigurationStatus_Accepted;
  15614. }
  15615. else
  15616. {
  15617. isSuccess = ConfigurationStatus_Rejected;
  15618. }
  15619. }
  15620. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15621. {
  15622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15623. {
  15624. check_ascii = value[0];
  15625. if( (check_ascii < 48) || (check_ascii > 57) )
  15626. {
  15627. isSuccess = ConfigurationStatus_Rejected;
  15628. }
  15629. else
  15630. {
  15631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15632. isSuccess = ConfigurationStatus_Accepted;
  15633. }
  15634. }
  15635. else
  15636. {
  15637. isSuccess = ConfigurationStatus_Rejected;
  15638. }
  15639. }
  15640. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15641. {
  15642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15643. {
  15644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15645. isSuccess = ConfigurationStatus_Accepted;
  15646. }
  15647. else
  15648. {
  15649. isSuccess = ConfigurationStatus_Rejected;
  15650. }
  15651. }
  15652. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15653. {
  15654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15655. {
  15656. check_ascii = value[0];
  15657. if( (check_ascii < 48) || (check_ascii > 57) )
  15658. {
  15659. isSuccess = ConfigurationStatus_Rejected;
  15660. }
  15661. else
  15662. {
  15663. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15665. isSuccess = ConfigurationStatus_Accepted;
  15666. }
  15667. }
  15668. else
  15669. {
  15670. isSuccess = ConfigurationStatus_Rejected;
  15671. }
  15672. }
  15673. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15674. {
  15675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15676. {
  15677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15678. isSuccess = ConfigurationStatus_Accepted;
  15679. }
  15680. else
  15681. {
  15682. isSuccess = ConfigurationStatus_Rejected;
  15683. }
  15684. }
  15685. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15686. {
  15687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15688. {
  15689. check_ascii = value[0];
  15690. if( (check_ascii < 48) || (check_ascii > 57) )
  15691. {
  15692. isSuccess = ConfigurationStatus_Rejected;
  15693. }
  15694. else
  15695. {
  15696. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15698. isSuccess = ConfigurationStatus_Accepted;
  15699. }
  15700. }
  15701. else
  15702. {
  15703. isSuccess = ConfigurationStatus_Rejected;
  15704. }
  15705. }
  15706. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15707. {
  15708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15709. {
  15710. check_ascii = value[0];
  15711. if( (check_ascii < 48) || (check_ascii > 57) )
  15712. {
  15713. isSuccess = ConfigurationStatus_Rejected;
  15714. }
  15715. else
  15716. {
  15717. if((atoi(value) == 0) || (atoi(value) >= 3))
  15718. {
  15719. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15721. isSuccess = ConfigurationStatus_Accepted;
  15722. }
  15723. else
  15724. {
  15725. isSuccess = ConfigurationStatus_Rejected;
  15726. }
  15727. }
  15728. }
  15729. else
  15730. {
  15731. isSuccess = ConfigurationStatus_Rejected;
  15732. }
  15733. }
  15734. if(strcmp(key, "MinimumStatusDuration") == 0)
  15735. {
  15736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15737. {
  15738. check_ascii = value[0];
  15739. if( (check_ascii < 48) || (check_ascii > 57) )
  15740. {
  15741. isSuccess = ConfigurationStatus_Rejected;
  15742. }
  15743. else
  15744. {
  15745. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15746. {
  15747. isSuccess = ConfigurationStatus_Rejected;
  15748. }
  15749. else
  15750. {
  15751. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15753. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15754. isSuccess = ConfigurationStatus_Accepted;
  15755. }
  15756. }
  15757. }
  15758. else
  15759. {
  15760. isSuccess = ConfigurationStatus_Rejected;
  15761. }
  15762. }
  15763. if(strcmp(key, "NumberOfConnectors") == 0)
  15764. {
  15765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15766. {
  15767. check_ascii = value[0];
  15768. if( (check_ascii < 48) || (check_ascii > 57) )
  15769. {
  15770. isSuccess = ConfigurationStatus_Rejected;
  15771. }
  15772. else
  15773. {
  15774. //Charger.ResetRetries = Integer.parseInt(value);
  15775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15776. isSuccess = ConfigurationStatus_Accepted;
  15777. }
  15778. }
  15779. else
  15780. {
  15781. isSuccess = ConfigurationStatus_Rejected;
  15782. }
  15783. }
  15784. if(strcmp(key, "ResetRetries") == 0)
  15785. {
  15786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15787. {
  15788. check_ascii = value[0];
  15789. if( (check_ascii < 48) || (check_ascii > 57) )
  15790. {
  15791. isSuccess = ConfigurationStatus_Rejected;
  15792. }
  15793. else
  15794. {
  15795. //Charger.ResetRetries = Integer.parseInt(value);
  15796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15797. isSuccess = ConfigurationStatus_Accepted;
  15798. }
  15799. }
  15800. else
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. }
  15805. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15806. {
  15807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15808. {
  15809. strcpy(str, (const char*)value);
  15810. for(int i = 0; str[i]; i++)
  15811. {
  15812. str[i] = tolower(str[i]);
  15813. }
  15814. if(strcmp(str, "notapplicable")== 0)
  15815. {
  15816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15817. isSuccess = ConfigurationStatus_Accepted;
  15818. }
  15819. else if(strcmp(str, "unknown")== 0)
  15820. {
  15821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15822. isSuccess = ConfigurationStatus_Accepted;
  15823. }
  15824. else if(strcmp(str, "rst")== 0)
  15825. {
  15826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15827. isSuccess = ConfigurationStatus_Accepted;
  15828. }
  15829. else if(strcmp(str, "rts")== 0)
  15830. {
  15831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15832. isSuccess = ConfigurationStatus_Accepted;
  15833. }
  15834. else if(strcmp(str, "srt")== 0)
  15835. {
  15836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15837. isSuccess = ConfigurationStatus_Accepted;
  15838. }
  15839. else if(strcmp(str, "str")== 0)
  15840. {
  15841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15842. isSuccess = ConfigurationStatus_Accepted;
  15843. }
  15844. else if(strcmp(str, "trs")== 0)
  15845. {
  15846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15847. isSuccess = ConfigurationStatus_Accepted;
  15848. }
  15849. else if(strcmp(str, "tsr")== 0)
  15850. {
  15851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15852. isSuccess = ConfigurationStatus_Accepted;
  15853. }
  15854. else
  15855. {
  15856. isSuccess = ConfigurationStatus_Rejected;
  15857. }
  15858. }
  15859. else
  15860. {
  15861. isSuccess = ConfigurationStatus_Rejected;
  15862. }
  15863. }
  15864. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15865. {
  15866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15867. {
  15868. check_ascii = value[0];
  15869. if( (check_ascii < 48) || (check_ascii > 57) )
  15870. {
  15871. isSuccess = ConfigurationStatus_Rejected;
  15872. }
  15873. else
  15874. {
  15875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15876. isSuccess = ConfigurationStatus_Accepted;
  15877. }
  15878. }
  15879. else
  15880. {
  15881. isSuccess = ConfigurationStatus_Rejected;
  15882. }
  15883. }
  15884. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15885. {
  15886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15887. {
  15888. strcpy(str, (const char*)value);
  15889. for(int i = 0; str[i]; i++)
  15890. {
  15891. str[i] = tolower(str[i]);
  15892. }
  15893. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15895. isSuccess = ConfigurationStatus_Accepted;
  15896. }
  15897. else
  15898. {
  15899. isSuccess = ConfigurationStatus_Rejected;
  15900. }
  15901. }
  15902. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15903. {
  15904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15905. {
  15906. strcpy(str, (const char*)value);
  15907. for(int i = 0; str[i]; i++)
  15908. {
  15909. str[i] = tolower(str[i]);
  15910. }
  15911. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15913. isSuccess = ConfigurationStatus_Accepted;
  15914. }
  15915. else
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. }
  15920. if(strcmp(key, "StopTxnAlignedData") == 0)
  15921. {
  15922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15923. {
  15924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15925. isSuccess = ConfigurationStatus_Accepted;
  15926. }
  15927. else
  15928. {
  15929. isSuccess = ConfigurationStatus_Rejected;
  15930. }
  15931. }
  15932. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15933. {
  15934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15935. {
  15936. check_ascii = value[0];
  15937. if( (check_ascii < 48) || (check_ascii > 57) )
  15938. {
  15939. isSuccess = ConfigurationStatus_Rejected;
  15940. }
  15941. else
  15942. {
  15943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15944. isSuccess = ConfigurationStatus_Accepted;
  15945. }
  15946. }
  15947. else
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. }
  15952. if(strcmp(key, "StopTxnSampledData") == 0)
  15953. {
  15954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15955. {
  15956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15957. isSuccess = ConfigurationStatus_Accepted;
  15958. }
  15959. else
  15960. {
  15961. isSuccess = ConfigurationStatus_Rejected;
  15962. }
  15963. }
  15964. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15965. {
  15966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15967. {
  15968. check_ascii = value[0];
  15969. if( (check_ascii < 48) || (check_ascii > 57) )
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. else
  15974. {
  15975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15976. isSuccess = ConfigurationStatus_Accepted;
  15977. }
  15978. }
  15979. else
  15980. {
  15981. isSuccess = ConfigurationStatus_Rejected;
  15982. }
  15983. }
  15984. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15985. {
  15986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15987. {
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15989. isSuccess = ConfigurationStatus_Accepted;
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15999. {
  16000. check_ascii = value[0];
  16001. if( (check_ascii < 48) || (check_ascii > 57) )
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. else
  16006. {
  16007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16008. isSuccess = ConfigurationStatus_Accepted;
  16009. }
  16010. }
  16011. else
  16012. {
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. }
  16016. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16017. {
  16018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16019. {
  16020. check_ascii = value[0];
  16021. if( (check_ascii < 48) || (check_ascii > 57) )
  16022. {
  16023. isSuccess = ConfigurationStatus_Rejected;
  16024. }
  16025. else
  16026. {
  16027. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16029. TransactionMessageAttemptsValue = atoi(value);
  16030. isSuccess = ConfigurationStatus_Accepted;
  16031. }
  16032. }
  16033. else
  16034. {
  16035. isSuccess = ConfigurationStatus_Rejected;
  16036. }
  16037. }
  16038. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16039. {
  16040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16041. {
  16042. check_ascii = value[0];
  16043. if( (check_ascii < 48) || (check_ascii > 57) )
  16044. {
  16045. isSuccess = ConfigurationStatus_Rejected;
  16046. }
  16047. else
  16048. {
  16049. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16051. TransactionMessageRetryIntervalValue = atoi(value);
  16052. isSuccess = ConfigurationStatus_Accepted;
  16053. }
  16054. }
  16055. else
  16056. {
  16057. isSuccess = ConfigurationStatus_Rejected;
  16058. }
  16059. }
  16060. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16061. {
  16062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16063. {
  16064. strcpy(str, (const char*)value);
  16065. for(int i = 0; str[i]; i++)
  16066. {
  16067. str[i] = tolower(str[i]);
  16068. }
  16069. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16071. isSuccess = ConfigurationStatus_Accepted;
  16072. }
  16073. else
  16074. {
  16075. isSuccess = ConfigurationStatus_Rejected;
  16076. }
  16077. }
  16078. if(strcmp(key, "WebSocketPingInterval") == 0)
  16079. {
  16080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16081. {
  16082. check_ascii = value[0];
  16083. if( (check_ascii < 48) || (check_ascii > 57) )
  16084. {
  16085. isSuccess = ConfigurationStatus_Rejected;
  16086. }
  16087. else
  16088. {
  16089. if((atoi(value) == 0) || (atoi(value) >= 10))
  16090. {
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16092. isSuccess = ConfigurationStatus_Accepted;
  16093. }
  16094. else
  16095. isSuccess = ConfigurationStatus_Rejected;
  16096. }
  16097. }
  16098. else
  16099. {
  16100. isSuccess = ConfigurationStatus_Rejected;
  16101. }
  16102. }
  16103. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16104. {
  16105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16106. {
  16107. strcpy(str, (const char*)value);
  16108. for(int i = 0; str[i]; i++)
  16109. {
  16110. str[i] = tolower(str[i]);
  16111. }
  16112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16113. isSuccess = ConfigurationStatus_Accepted;
  16114. }
  16115. else
  16116. {
  16117. isSuccess = ConfigurationStatus_Rejected;
  16118. }
  16119. }
  16120. if(strcmp(key, "AuthorizationKey") == 0)
  16121. {
  16122. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16123. {
  16124. strcpy(str, (const char*)value);
  16125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16126. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. else
  16130. {
  16131. isSuccess = ConfigurationStatus_Rejected;
  16132. }
  16133. }
  16134. if(strcmp(key, "SecurityProfile") == 0)
  16135. {
  16136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16137. {
  16138. check_ascii = value[0];
  16139. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16140. {
  16141. isSuccess = ConfigurationStatus_Rejected;
  16142. }
  16143. else if(check_ascii == 0x33)
  16144. {
  16145. isSuccess = NotSupported;
  16146. }
  16147. else
  16148. {
  16149. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16150. {
  16151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16152. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16153. isSuccess = ConfigurationStatus_Accepted;
  16154. }
  16155. else
  16156. isSuccess = ConfigurationStatus_Rejected;
  16157. }
  16158. }
  16159. else
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. }
  16164. if(strcmp(key, "DefaultPrice") == 0)
  16165. {
  16166. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16167. {
  16168. strcpy(str, (const char*)value);
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16170. isSuccess = ConfigurationStatus_Accepted;
  16171. }
  16172. else
  16173. {
  16174. isSuccess = ConfigurationStatus_Rejected;
  16175. }
  16176. }
  16177. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16178. {
  16179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16180. {
  16181. strcpy(str, (const char*)value);
  16182. for(int i = 0; str[i]; i++)
  16183. {
  16184. str[i] = tolower(str[i]);
  16185. }
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16187. isSuccess = ConfigurationStatus_Accepted;
  16188. }
  16189. else
  16190. {
  16191. isSuccess = ConfigurationStatus_Rejected;
  16192. }
  16193. }
  16194. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16195. {
  16196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16197. {
  16198. strcpy(str, (const char*)value);
  16199. for(int i = 0; str[i]; i++)
  16200. {
  16201. str[i] = tolower(str[i]);
  16202. }
  16203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16204. isSuccess = ConfigurationStatus_Accepted;
  16205. }
  16206. else
  16207. {
  16208. isSuccess = ConfigurationStatus_Rejected;
  16209. }
  16210. }
  16211. if(strcmp(key, "TimeOffset") == 0)
  16212. {
  16213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16214. {
  16215. strcpy(str, (const char*)value);
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16217. isSuccess = ConfigurationStatus_Accepted;
  16218. }
  16219. else
  16220. {
  16221. isSuccess = ConfigurationStatus_Rejected;
  16222. }
  16223. }
  16224. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16225. {
  16226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16227. {
  16228. strcpy(str, (const char*)value);
  16229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16230. isSuccess = ConfigurationStatus_Accepted;
  16231. }
  16232. else
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. }
  16237. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16238. {
  16239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16240. {
  16241. strcpy(str, (const char*)value);
  16242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16243. isSuccess = ConfigurationStatus_Accepted;
  16244. }
  16245. else
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. }
  16250. if(strcmp(key, "SystemUptimeSec") == 0)
  16251. {
  16252. isSuccess = NotSupported;
  16253. }
  16254. if(strcmp(key, "FreeVend") == 0)
  16255. {
  16256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16257. {
  16258. strcpy(str, (const char*)value);
  16259. for(int i = 0; str[i]; i++)
  16260. {
  16261. str[i] = tolower(str[i]);
  16262. }
  16263. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16265. isSuccess = ConfigurationStatus_Accepted;
  16266. }
  16267. else
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. }
  16272. if(strcmp(key, "OcppServer") == 0)
  16273. {
  16274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16275. {
  16276. strcpy(str, (const char*)value);
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16278. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. else
  16282. {
  16283. isSuccess = ConfigurationStatus_Rejected;
  16284. }
  16285. }
  16286. if(strcmp(key, "MaintainServer") == 0)
  16287. {
  16288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16289. {
  16290. strcpy(str, (const char*)value);
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16292. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16293. isSuccess = ConfigurationStatus_Accepted;
  16294. }
  16295. else
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. }
  16300. #if 0
  16301. //For OCPP Test Case
  16302. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16303. {
  16304. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16305. {
  16306. strcpy(str, (const char*)value);
  16307. for(int i = 0; str[i]; i++)
  16308. {
  16309. str[i] = tolower(str[i]);
  16310. }
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16312. isSuccess = ConfigurationStatus_Accepted;
  16313. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16314. }
  16315. else
  16316. {
  16317. isSuccess = ConfigurationStatus_Rejected;
  16318. }
  16319. }
  16320. #endif
  16321. #if 1
  16322. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16323. {
  16324. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16325. {
  16326. strcpy(str, (const char*)value);
  16327. for(int i = 0; str[i]; i++)
  16328. {
  16329. str[i] = tolower(str[i]);
  16330. }
  16331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16332. isSuccess = ConfigurationStatus_Accepted;
  16333. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16334. }
  16335. else
  16336. {
  16337. isSuccess = ConfigurationStatus_Rejected;
  16338. }
  16339. }
  16340. #endif
  16341. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16342. {
  16343. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16344. {
  16345. check_ascii = value[0];
  16346. if( (check_ascii < 48) || (check_ascii > 57) )
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. else
  16351. {
  16352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16353. isSuccess = ConfigurationStatus_Accepted;
  16354. }
  16355. }
  16356. else
  16357. {
  16358. isSuccess = ConfigurationStatus_Rejected;
  16359. }
  16360. }
  16361. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16362. {
  16363. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16364. {
  16365. check_ascii = value[0];
  16366. if( (check_ascii < 48) || (check_ascii > 57) )
  16367. {
  16368. isSuccess = ConfigurationStatus_Rejected;
  16369. }
  16370. else
  16371. {
  16372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16373. isSuccess = ConfigurationStatus_Accepted;
  16374. }
  16375. }
  16376. else
  16377. {
  16378. isSuccess = ConfigurationStatus_Rejected;
  16379. }
  16380. }
  16381. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16382. {
  16383. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16384. {
  16385. strcpy(str, (const char*)value);
  16386. for(int i = 0; str[i]; i++)
  16387. {
  16388. str[i] = tolower(str[i]);
  16389. }
  16390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16391. isSuccess = ConfigurationStatus_Accepted;
  16392. }
  16393. else
  16394. {
  16395. isSuccess = ConfigurationStatus_Rejected;
  16396. }
  16397. }
  16398. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16399. {
  16400. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16401. {
  16402. check_ascii = value[0];
  16403. if( (check_ascii < 48) || (check_ascii > 57) )
  16404. {
  16405. isSuccess = ConfigurationStatus_Rejected;
  16406. }
  16407. else
  16408. {
  16409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16410. isSuccess = ConfigurationStatus_Accepted;
  16411. }
  16412. }
  16413. else
  16414. {
  16415. isSuccess = ConfigurationStatus_Rejected;
  16416. }
  16417. }
  16418. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16419. {
  16420. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16421. {
  16422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16423. isSuccess = ConfigurationStatus_Accepted;
  16424. }
  16425. else
  16426. {
  16427. isSuccess = ConfigurationStatus_Rejected;
  16428. }
  16429. }
  16430. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16431. {
  16432. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16442. isSuccess = ConfigurationStatus_Accepted;
  16443. }
  16444. }
  16445. else
  16446. {
  16447. isSuccess = ConfigurationStatus_Rejected;
  16448. }
  16449. }
  16450. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16451. {
  16452. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16453. {
  16454. strcpy(str, (const char*)value);
  16455. for(int i = 0; str[i]; i++)
  16456. {
  16457. str[i] = tolower(str[i]);
  16458. }
  16459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16460. isSuccess = ConfigurationStatus_Accepted;
  16461. }
  16462. else
  16463. {
  16464. isSuccess = ConfigurationStatus_Rejected;
  16465. }
  16466. }
  16467. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16468. {
  16469. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16470. {
  16471. check_ascii = value[0];
  16472. if( (check_ascii < 48) || (check_ascii > 57) )
  16473. {
  16474. isSuccess = ConfigurationStatus_Rejected;
  16475. }
  16476. else
  16477. {
  16478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16479. isSuccess = ConfigurationStatus_Accepted;
  16480. }
  16481. }
  16482. else
  16483. {
  16484. isSuccess = ConfigurationStatus_Rejected;
  16485. }
  16486. }
  16487. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16488. return isSuccess;
  16489. }
  16490. int TransactionMessageAttemptsGet(void)
  16491. {
  16492. return TransactionMessageAttemptsValue;
  16493. }
  16494. int FirstHeartBeatResponse(void)
  16495. {
  16496. return FirstHeartBeat;
  16497. }
  16498. int TransactionMessageRetryIntervalGet(void)
  16499. {
  16500. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16501. }
  16502. int ReadHttpStatus(int sock)
  16503. {
  16504. //char c;
  16505. char buff[1024]="",*ptr=buff+1;
  16506. int bytes_received, status;
  16507. DEBUG_INFO("Begin Response ..\n");
  16508. while((bytes_received = recv(sock, ptr, 1, 0))){
  16509. if(bytes_received==-1){
  16510. perror("ReadHttpStatus");
  16511. exit(1);
  16512. }
  16513. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16514. ptr++;
  16515. }
  16516. *ptr=0;
  16517. ptr=buff+1;
  16518. sscanf(ptr,"%*s %d ", &status);
  16519. DEBUG_INFO("%s\n",ptr);
  16520. DEBUG_INFO("status=%d\n",status);
  16521. DEBUG_INFO("End Response ..\n");
  16522. return (bytes_received>0)?status:0;
  16523. }
  16524. //the only filed that it parsed is 'Content-Length'
  16525. int ParseHeader(int sock)
  16526. {
  16527. //char c;
  16528. char buff[1024]="",*ptr=buff+4;
  16529. int bytes_received;
  16530. DEBUG_INFO("Begin HEADER ..\n");
  16531. while((bytes_received = recv(sock, ptr, 1, 0))){
  16532. if(bytes_received==-1){
  16533. perror("Parse Header");
  16534. exit(1);
  16535. }
  16536. if(
  16537. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16538. (ptr[-1]=='\r') && (*ptr=='\n' )
  16539. ) break;
  16540. ptr++;
  16541. }
  16542. *ptr=0;
  16543. ptr=buff+4;
  16544. //printf("%s",ptr);
  16545. if(bytes_received){
  16546. ptr=strstr(ptr,"Content-Length:");
  16547. if(ptr){
  16548. sscanf(ptr,"%*s %d",&bytes_received);
  16549. }else
  16550. bytes_received=-1; //unknown size
  16551. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16552. }
  16553. DEBUG_INFO("End HEADER ..\n");
  16554. return bytes_received ;
  16555. }
  16556. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16557. {
  16558. int result = TRUE;
  16559. char rmFileCmd[100]={0};
  16560. char FilePath[100]={0};
  16561. char ftpbuf[200];
  16562. int systemresult;
  16563. sprintf(FilePath,"/mnt/%s",filename);
  16564. system("ping 8.8.8.8 &");
  16565. if((access(FilePath,F_OK))!=-1)
  16566. {
  16567. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16568. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16569. system(rmFileCmd);
  16570. }
  16571. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16572. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16573. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16574. systemresult = system(ftpbuf);
  16575. if(systemresult != 0)
  16576. {
  16577. DEBUG_INFO("http DownLoad error!\n");
  16578. result = FALSE;
  16579. }
  16580. system("pkill ping");
  16581. return result;
  16582. }
  16583. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16584. {
  16585. int result = TRUE;
  16586. char rmFileCmd[100]={0};
  16587. char FilePath[100]={0};
  16588. char ftpbuf[200];
  16589. int systemresult;
  16590. sprintf(FilePath,"/mnt/%s",filename);
  16591. system("ping 8.8.8.8 &");
  16592. if((access(FilePath,F_OK))!=-1)
  16593. {
  16594. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16595. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16596. system(rmFileCmd);
  16597. }
  16598. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16599. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16600. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16601. systemresult = system(ftpbuf);
  16602. if(systemresult != 0)
  16603. {
  16604. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16605. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16606. systemresult = system(ftpbuf);
  16607. if(systemresult != 0)
  16608. {
  16609. DEBUG_WARN("wget error!\n");
  16610. result = FALSE;
  16611. }
  16612. }
  16613. system("pkill ping");
  16614. return result;
  16615. }
  16616. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16617. {
  16618. char rmFileCmd[100]={0};
  16619. char FilePath[100]={0};
  16620. char buf[512];
  16621. int systemresult = 0;
  16622. //DEBUG_INFO("filename=%s\n",filename);
  16623. //DEBUG_INFO("url=%s\n",url);
  16624. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16625. if((access(FilePath,F_OK))!=-1)
  16626. {
  16627. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16628. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16629. system(rmFileCmd);
  16630. }
  16631. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16632. if(fp == NULL)
  16633. {
  16634. DEBUG_INFO("log is NULL\n");
  16635. return FALSE;
  16636. }
  16637. else
  16638. {
  16639. fprintf(fp, "%s\n", url);
  16640. fprintf(fp, "%s\n", filename);
  16641. fclose(fp);
  16642. }
  16643. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16644. if(phpFP == NULL)
  16645. {
  16646. DEBUG_INFO("PHP upload fail.\n");
  16647. return FALSE;
  16648. }
  16649. else
  16650. {
  16651. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16652. {
  16653. if(strstr(buf, "result") != NULL)
  16654. {
  16655. sscanf(buf, "result: %d", &systemresult);
  16656. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16657. }
  16658. }
  16659. pclose(phpFP);
  16660. }
  16661. if(systemresult != 1)
  16662. {
  16663. DEBUG_INFO("HTTP upload error!\n");
  16664. return FALSE;
  16665. }
  16666. return TRUE;
  16667. }
  16668. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16669. {
  16670. int result = FALSE;
  16671. char ftpbuf[200];
  16672. int systemresult;
  16673. /*
  16674. // Domaind name transfer to IP address
  16675. struct hostent* server;
  16676. char *IPbuffer;
  16677. server = gethostbyname(location);
  16678. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16679. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16680. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16681. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16682. systemresult = system(ftpbuf);
  16683. if(systemresult != 0)
  16684. {
  16685. DEBUG_INFO("ftpput error!\n");
  16686. }
  16687. else
  16688. {
  16689. result = TRUE;
  16690. DEBUG_INFO("ftpput OK!\n");
  16691. }
  16692. return result;
  16693. }
  16694. int GetOcppServerURL()
  16695. {
  16696. int result = FALSE;
  16697. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16698. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16699. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16700. struct yuarel url;
  16701. char urlStr[512];
  16702. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16703. {
  16704. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16705. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16706. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16707. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16708. if(yuarel_parse(&url, urlStr) != -1)
  16709. {
  16710. sprintf(OcppProtocol, "%s", url.scheme);
  16711. sprintf(OcppHost, "%s", url.host);
  16712. if(url.path == NULL)
  16713. OcppTempPath[0] = '\0';
  16714. else
  16715. {
  16716. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16717. {
  16718. sprintf(OcppTempPath, "%s/", url.path);
  16719. }
  16720. else
  16721. {
  16722. sprintf(OcppTempPath, "%s", url.path);
  16723. }
  16724. }
  16725. if(url.port == 0)
  16726. {
  16727. if(strcmp(OcppProtocol, "wss") == 0)
  16728. OcppPort = 443;
  16729. else
  16730. OcppPort = 80;
  16731. }
  16732. else
  16733. OcppPort = url.port;
  16734. result = TRUE;
  16735. }
  16736. }
  16737. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16738. {
  16739. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16740. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16741. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16742. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16743. if(yuarel_parse(&url, urlStr) != -1)
  16744. {
  16745. sprintf(OcppProtocol, "%s", url.scheme);
  16746. sprintf(OcppHost, "%s", url.host);
  16747. if(url.path == NULL)
  16748. OcppTempPath[0] = '\0';
  16749. else
  16750. sprintf(OcppTempPath, "%s", url.path);
  16751. if(url.port == 0)
  16752. {
  16753. if(strcmp(OcppProtocol, "wss") == 0)
  16754. OcppPort = 443;
  16755. else
  16756. OcppPort = 80;
  16757. }
  16758. else
  16759. OcppPort = url.port;
  16760. result = TRUE;
  16761. }
  16762. }
  16763. else
  16764. {
  16765. strcpy(OcppHost,"");
  16766. }
  16767. return result;
  16768. }
  16769. int GetOcppPath()
  16770. {
  16771. int result = FALSE;
  16772. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16773. {
  16774. if(OcppTempPath == NULL)
  16775. {
  16776. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16777. }
  16778. else
  16779. {
  16780. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16781. }
  16782. result = TRUE;
  16783. goto End;
  16784. }
  16785. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16786. {
  16787. if(OcppTempPath == NULL)
  16788. {
  16789. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16790. }
  16791. else
  16792. {
  16793. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16794. }
  16795. result = TRUE;
  16796. goto End;
  16797. }
  16798. else
  16799. {
  16800. strcpy(OcppPath,"");
  16801. }
  16802. End:
  16803. return result;
  16804. }
  16805. int GetOcppPort()
  16806. {
  16807. return OcppPort;
  16808. }
  16809. int GetOcppConnStatus(void)
  16810. {
  16811. return ShmOCPP16Data->OcppConnStatus;
  16812. }
  16813. void SetOcppConnStatus(uint8_t status)
  16814. {
  16815. ShmOCPP16Data->OcppConnStatus = status;
  16816. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16817. }
  16818. int GetHeartBeatWithNOResponse(void)
  16819. {
  16820. return HeartBeatWithNOResponse;
  16821. }
  16822. void SetHeartBeatWithNOResponse(void)
  16823. {
  16824. HeartBeatWithNOResponse = 0;
  16825. }
  16826. void GetStartTransactionIdTag(int gun_index)
  16827. {
  16828. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16829. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16830. }
  16831. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16832. {
  16833. char ch;
  16834. FILE *fptr1;
  16835. int temptransactionId;
  16836. char str[100]={0};
  16837. temptransactionId = 0;
  16838. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16839. {
  16840. DEBUG_INFO("IdTag is empty.\n");
  16841. return temptransactionId;
  16842. }
  16843. /*------ Read the file ----------------*/
  16844. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16845. if (!fptr1)
  16846. {
  16847. DEBUG_INFO("QueueTransactionId file open error.\n");
  16848. //printf(" File not found or unable to open the input file!!\n");
  16849. return temptransactionId;
  16850. }
  16851. ch=fgetc(fptr1);
  16852. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16853. rewind(fptr1);
  16854. if(ch!=EOF)
  16855. {
  16856. // printf("%c",ch);
  16857. while (fgets(str, 100, fptr1) != NULL)
  16858. {
  16859. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16860. if(str[0]=='\0')
  16861. {
  16862. break;
  16863. }
  16864. char *revbuf[8] = {0}; // Variable store string split
  16865. int num = 0;// Quantity after string split
  16866. DEBUG_INFO("Transaction queue data= %s\n", str);
  16867. splitstring(str,",",revbuf,&num); // String split
  16868. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16869. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16870. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16871. DEBUG_INFO("------------------------------\n");
  16872. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16873. {
  16874. if(isStopTransaction)
  16875. {
  16876. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16877. {
  16878. temptransactionId = atoi(revbuf[2]);
  16879. //break;
  16880. }
  16881. }
  16882. else
  16883. {
  16884. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16885. {
  16886. temptransactionId = atoi(revbuf[2]);
  16887. //break;
  16888. }
  16889. }
  16890. }
  16891. }
  16892. }
  16893. else
  16894. DEBUG_INFO("EOF\n");
  16895. fclose(fptr1);
  16896. /*------- End of reading ---------------*/
  16897. return temptransactionId;
  16898. }
  16899. void SetTransactionIdZero(int transactionId)
  16900. {
  16901. char ch;
  16902. FILE *fptr1, *fptr2;
  16903. int temptransactionId = 0;
  16904. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16905. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16906. if (!fptr1)
  16907. {
  16908. //printf(" File not found or unable to open the input file!!\n");
  16909. return ;
  16910. }
  16911. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16912. if (!fptr2)
  16913. {
  16914. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16915. fclose(fptr1);
  16916. return ;
  16917. }
  16918. ch=fgetc(fptr1);
  16919. rewind(fptr1);
  16920. if(ch!=EOF)
  16921. {
  16922. // copy all contents to the temporary file except the specific line
  16923. while (fgets(str, 100, fptr1) != NULL)
  16924. {
  16925. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16926. if(str[0]=='\0')
  16927. {
  16928. break;
  16929. }
  16930. char *revbuf[8] = {0};
  16931. int num = 0;
  16932. strcpy(strtemp, str);
  16933. splitstring(str,",",revbuf,&num);
  16934. if(revbuf[2][0] != '\0')
  16935. {
  16936. temptransactionId = atoi(revbuf[2]);
  16937. if(transactionId != temptransactionId)
  16938. {
  16939. fprintf(fptr2, "%s\n", strtemp);
  16940. }
  16941. }
  16942. }
  16943. }
  16944. fclose(fptr1);
  16945. fclose(fptr2);
  16946. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16947. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16948. /*------ Read the file ----------------*/
  16949. }
  16950. int InternetDisconnect(void)
  16951. {
  16952. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16953. }
  16954. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16955. void storeTempStopTransaction(int gun_index)
  16956. {
  16957. char guid[37]={0};
  16958. int tempIndex = 0;
  16959. char TempStopTransaction[256];
  16960. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16961. DEBUG_INFO("storeTempStopTransaction...\n");
  16962. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16963. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16964. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16965. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16966. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16967. {
  16968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16969. {
  16970. tempIndex = ((gun_index==2) ? 1: 0);
  16971. }
  16972. else
  16973. {
  16974. tempIndex = gun_index;
  16975. }
  16976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16977. {
  16978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16979. {
  16980. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16981. }
  16982. }// END OF CHAdeMO_QUANTITY
  16983. }
  16984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16985. {
  16986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16987. {
  16988. tempIndex = ((gun_index==2) ? 1: 0);
  16989. }
  16990. else
  16991. {
  16992. tempIndex = gun_index;
  16993. }
  16994. for (int index = 0; index < CCS_QUANTITY; index++)
  16995. {
  16996. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16997. {
  16998. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16999. }
  17000. }// END OF CCS_QUANTITY
  17001. }
  17002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17003. {
  17004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17005. {
  17006. tempIndex = ((gun_index==2) ? 1: 0);
  17007. }
  17008. else
  17009. {
  17010. tempIndex = gun_index;
  17011. }
  17012. for (int index = 0; index < GB_QUANTITY; index++)
  17013. {
  17014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17015. {
  17016. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17017. }
  17018. }// END OF GB_QUANTITY
  17019. }
  17020. else if(gunType[gun_index] == GUN_TYPE_DO)
  17021. {
  17022. tempIndex = gun_index;
  17023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17024. {
  17025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17026. {
  17027. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17028. }
  17029. }
  17030. }
  17031. else
  17032. {
  17033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17034. {
  17035. tempIndex = 2;
  17036. }
  17037. else
  17038. {
  17039. tempIndex = gun_index;
  17040. }
  17041. for (int index = 0; index < AC_QUANTITY; index++)
  17042. {
  17043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17044. {
  17045. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17046. }
  17047. }// END OF AC_QUANTITY
  17048. }
  17049. //Stop Transaction Time
  17050. struct timeval tmnow;
  17051. struct tm *tm;
  17052. char buf[28];//, usec_buf[6];
  17053. gettimeofday(&tmnow, NULL);
  17054. time_t t;
  17055. t = time(NULL);
  17056. /*UTC time and date*/
  17057. tm = gmtime(&t);
  17058. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17060. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17062. random_uuid(guid);
  17063. /***********************************transactionData******************************************************/
  17064. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17066. //=================================
  17067. //1. Transaction_Begin
  17068. //=================================
  17069. //============================== Energy.Active.Import.Interval ===========================================
  17070. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17071. {
  17072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17075. 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*/]);
  17076. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17077. 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))
  17078. {
  17079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17080. }
  17081. else
  17082. {
  17083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17084. }
  17085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17087. }
  17088. //=================================
  17089. //2. Transaction_End
  17090. //=================================
  17091. //2.1====================================== Current.Import L1 ==============================================
  17092. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17093. {
  17094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17096. {
  17097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17098. {
  17099. tempIndex = ((gun_index==2) ? 1: 0);
  17100. }
  17101. else
  17102. {
  17103. tempIndex = gun_index;
  17104. }
  17105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17106. {
  17107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17108. {
  17109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17110. }
  17111. }// End of for CHAdeMO_QUANTITY
  17112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17113. }
  17114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17115. {
  17116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17117. {
  17118. tempIndex = ((gun_index==2) ? 1: 0);
  17119. }
  17120. else
  17121. {
  17122. tempIndex = gun_index;
  17123. }
  17124. for (int index = 0; index < CCS_QUANTITY; index++)
  17125. {
  17126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17127. {
  17128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17129. }
  17130. }// End of for CCS_QUANTITY
  17131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17132. }
  17133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17134. {
  17135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17136. {
  17137. tempIndex = ((gun_index==2) ? 1: 0);
  17138. }
  17139. else
  17140. {
  17141. tempIndex = gun_index;
  17142. }
  17143. for (int index = 0; index < GB_QUANTITY; index++)
  17144. {
  17145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17146. {
  17147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17148. }
  17149. }// End of for GB_QUANTITY
  17150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17151. }
  17152. else if(gunType[gun_index] == GUN_TYPE_DO)
  17153. {
  17154. tempIndex = gun_index;
  17155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17156. {
  17157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17158. {
  17159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17160. }
  17161. }
  17162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17163. }
  17164. else
  17165. {
  17166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17167. {
  17168. tempIndex = 2;
  17169. }
  17170. else
  17171. {
  17172. tempIndex = gun_index;
  17173. }
  17174. for (int index = 0; index < AC_QUANTITY; index++)
  17175. {
  17176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17177. {
  17178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17179. }
  17180. }// End of for AC_QUANTITY
  17181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17182. }
  17183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17186. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17189. }
  17190. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17191. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17192. {
  17193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17195. {
  17196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17197. {
  17198. tempIndex = ((gun_index==2) ? 1: 0);
  17199. }
  17200. else
  17201. {
  17202. tempIndex = gun_index;
  17203. }
  17204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17205. {
  17206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17207. {
  17208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17209. }
  17210. }// END OF CHAdeMO_QUANTITY
  17211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17212. }
  17213. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17214. {
  17215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17216. {
  17217. tempIndex = ((gun_index==2) ? 1: 0);
  17218. }
  17219. else
  17220. {
  17221. tempIndex = gun_index;
  17222. }
  17223. for (int index = 0; index < CCS_QUANTITY; index++)
  17224. {
  17225. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17226. {
  17227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17228. }
  17229. }// END OF CCS_QUANTITY
  17230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17231. }
  17232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17233. {
  17234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17235. {
  17236. tempIndex = ((gun_index==2) ? 1: 0);
  17237. }
  17238. else
  17239. {
  17240. tempIndex = gun_index;
  17241. }
  17242. for (int index = 0; index < GB_QUANTITY; index++)
  17243. {
  17244. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17245. {
  17246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17247. }
  17248. }// END OF GB_QUANTITY
  17249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17250. }
  17251. else if(gunType[gun_index] == GUN_TYPE_DO)
  17252. {
  17253. tempIndex = gun_index;
  17254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17255. {
  17256. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17257. {
  17258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17259. }
  17260. }
  17261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17262. }
  17263. else
  17264. {
  17265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17266. {
  17267. tempIndex = 2;
  17268. }
  17269. else
  17270. {
  17271. tempIndex = gun_index;
  17272. }
  17273. for (int index = 0; index < AC_QUANTITY; index++)
  17274. {
  17275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17276. {
  17277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17278. }
  17279. }// END OF AC_QUANTITY
  17280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17281. }
  17282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17285. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17288. }
  17289. //2.3====================================== Power.Active.Import =========================================
  17290. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17291. {
  17292. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17293. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17294. {
  17295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17296. {
  17297. tempIndex = ((gun_index==2) ? 1: 0);
  17298. }
  17299. else
  17300. {
  17301. tempIndex = gun_index;
  17302. }
  17303. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17304. {
  17305. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17306. {
  17307. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17308. }
  17309. } // End for CHAdeMO_QUANTITY
  17310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17311. }
  17312. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17313. {
  17314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17315. {
  17316. tempIndex = ((gun_index==2) ? 1: 0);
  17317. }
  17318. else
  17319. {
  17320. tempIndex = gun_index;
  17321. }
  17322. for (int index = 0; index < CCS_QUANTITY; index++)
  17323. {
  17324. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17325. {
  17326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17327. }
  17328. } // END for CCS_QUANTITY
  17329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17330. }
  17331. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17332. {
  17333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17334. {
  17335. tempIndex = ((gun_index==2) ? 1: 0);
  17336. }
  17337. else
  17338. {
  17339. tempIndex = gun_index;
  17340. }
  17341. for (int index = 0; index < GB_QUANTITY; index++)
  17342. {
  17343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17344. {
  17345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17346. }
  17347. }// END for GB_QUANTITY
  17348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17349. }
  17350. else if(gunType[gun_index] == GUN_TYPE_DO)
  17351. {
  17352. tempIndex = gun_index;
  17353. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17354. {
  17355. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17356. {
  17357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17358. }
  17359. }
  17360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17361. }
  17362. else
  17363. {
  17364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17365. {
  17366. tempIndex = 2;
  17367. }
  17368. else
  17369. {
  17370. tempIndex = gun_index;
  17371. }
  17372. for (int index = 0; index < AC_QUANTITY; index++)
  17373. {
  17374. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17375. {
  17376. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17377. }
  17378. } // END for AC_QUANTITY
  17379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17380. }
  17381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17384. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17387. }
  17388. //2.4====================================== Voltage L1 ====================================================
  17389. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17390. {
  17391. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17393. {
  17394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17395. {
  17396. tempIndex = ((gun_index==2) ? 1: 0);
  17397. }
  17398. else
  17399. {
  17400. tempIndex = gun_index;
  17401. }
  17402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17403. {
  17404. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17405. {
  17406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17407. }
  17408. } // END OF FOR CHAdeMO_QUANTITY
  17409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17410. }
  17411. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17412. {
  17413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17414. {
  17415. tempIndex = ((gun_index==2) ? 1: 0);
  17416. }
  17417. else
  17418. {
  17419. tempIndex = gun_index;
  17420. }
  17421. for (int index = 0; index < CCS_QUANTITY; index++)
  17422. {
  17423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17424. {
  17425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17426. }
  17427. } // END OF FOR CCS_QUANTITY
  17428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17429. }
  17430. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17431. {
  17432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17433. {
  17434. tempIndex = ((gun_index==2) ? 1: 0);
  17435. }
  17436. else
  17437. {
  17438. tempIndex = gun_index;
  17439. }
  17440. for (int index = 0; index < GB_QUANTITY; index++)
  17441. {
  17442. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17443. {
  17444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17445. }
  17446. } // END OF FOR GB_QUANTITY
  17447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17448. }
  17449. else if(gunType[gun_index] == GUN_TYPE_DO)
  17450. {
  17451. tempIndex = gun_index;
  17452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17453. {
  17454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17455. {
  17456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17457. }
  17458. }
  17459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17460. }
  17461. else
  17462. {
  17463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17464. {
  17465. tempIndex = 2;
  17466. }
  17467. else
  17468. {
  17469. tempIndex = gun_index;
  17470. }
  17471. for (int index = 0; index < AC_QUANTITY; index++)
  17472. {
  17473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17474. {
  17475. 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
  17476. }
  17477. } // END OF FOR AC_QUANTITY
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17479. }
  17480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17483. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17486. }
  17487. //2.5============================================== End SoC =========================================================
  17488. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17489. {
  17490. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17491. 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))
  17492. {
  17493. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17494. {
  17495. tempIndex = ((gun_index==2) ? 1: 0);
  17496. }
  17497. else
  17498. {
  17499. tempIndex = gun_index;
  17500. }
  17501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17502. {
  17503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17504. {
  17505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17506. {
  17507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17508. }
  17509. }
  17510. }
  17511. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17512. {
  17513. for (int index = 0; index < CCS_QUANTITY; index++)
  17514. {
  17515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17516. {
  17517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17518. }
  17519. }
  17520. }
  17521. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17522. {
  17523. for (int index = 0; index < GB_QUANTITY; index++)
  17524. {
  17525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17526. {
  17527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17528. }
  17529. }
  17530. }
  17531. else if(gunType[gun_index] == GUN_TYPE_DO)
  17532. {
  17533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17534. {
  17535. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17536. {
  17537. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17538. }
  17539. }
  17540. }
  17541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17547. } // END FOR DC CASE
  17548. }
  17549. //2.6====================================== Current.Import L2 ==============================================
  17550. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17551. {
  17552. // AC 3 phase L2 current
  17553. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17554. {
  17555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17556. {
  17557. tempIndex = 2;
  17558. }
  17559. else
  17560. {
  17561. tempIndex = gun_index;
  17562. }
  17563. for (int index = 0; index < AC_QUANTITY; index++)
  17564. {
  17565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17566. {
  17567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17568. }
  17569. }// End of for AC_QUANTITY
  17570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17571. }
  17572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17577. }
  17578. //2.7====================================== Current.Import L3 ==============================================
  17579. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17580. {
  17581. // AC 3 phase L3 current
  17582. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17583. {
  17584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17585. {
  17586. tempIndex = 2;
  17587. }
  17588. else
  17589. {
  17590. tempIndex = gun_index;
  17591. }
  17592. for (int index = 0; index < AC_QUANTITY; index++)
  17593. {
  17594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17595. {
  17596. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17597. }
  17598. }// End of for AC_QUANTITY
  17599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17600. }
  17601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17606. }
  17607. //2.9====================================== Voltage L2 ====================================================
  17608. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17609. {
  17610. // AC 3 phase L2 volatge
  17611. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17612. {
  17613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17614. {
  17615. tempIndex = 2;
  17616. }
  17617. else
  17618. {
  17619. tempIndex = gun_index;
  17620. }
  17621. for (int index = 0; index < AC_QUANTITY; index++)
  17622. {
  17623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17624. {
  17625. 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
  17626. }
  17627. } // END OF FOR AC_QUANTITY
  17628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17629. }
  17630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17635. }
  17636. //2.10====================================== Voltage L3 ====================================================
  17637. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17638. {
  17639. // AC 3 phase L3 volatge
  17640. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17641. {
  17642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17643. {
  17644. tempIndex = 2;
  17645. }
  17646. else
  17647. {
  17648. tempIndex = gun_index;
  17649. }
  17650. for (int index = 0; index < AC_QUANTITY; index++)
  17651. {
  17652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17653. {
  17654. 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
  17655. }
  17656. } // END OF FOR AC_QUANTITY
  17657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17658. }
  17659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17664. }
  17665. //====================== Start SoC ================================
  17666. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17667. {
  17668. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17669. 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))
  17670. {
  17671. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17672. {
  17673. tempIndex = ((gun_index==2) ? 1: 0);
  17674. }
  17675. else
  17676. {
  17677. tempIndex = gun_index;
  17678. }
  17679. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17680. {
  17681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17682. {
  17683. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17684. {
  17685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17686. }
  17687. }
  17688. }
  17689. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17690. {
  17691. for (int index = 0; index < CCS_QUANTITY; index++)
  17692. {
  17693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17694. {
  17695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17696. }
  17697. }
  17698. }
  17699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17700. {
  17701. for (int index = 0; index < GB_QUANTITY; index++)
  17702. {
  17703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17704. {
  17705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17706. }
  17707. }
  17708. }
  17709. else if(gunType[gun_index] == GUN_TYPE_DO)
  17710. {
  17711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17712. {
  17713. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17714. {
  17715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17716. }
  17717. }
  17718. }
  17719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17725. } // END FOR DC CASE
  17726. }
  17727. //======================================== Message create ==============================================
  17728. json_object *StopTransaction = json_object_new_object();
  17729. json_object *transactionDatas = json_object_new_array();
  17730. json_object *sampledValues = json_object_new_array();
  17731. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17732. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17733. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17734. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17735. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17736. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17737. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17738. {
  17739. json_object *transactionData = json_object_new_object();
  17740. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17741. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17742. {
  17743. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17744. {
  17745. json_object *sampledValue = json_object_new_object();
  17746. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17747. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17748. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17749. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17750. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17751. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17752. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17753. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17754. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17755. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17756. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17758. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17759. json_object_array_add(sampledValues, sampledValue);
  17760. }
  17761. }
  17762. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17763. json_object_array_add(transactionDatas, transactionData);
  17764. }
  17765. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17766. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17767. ,MESSAGE_TYPE_CALL
  17768. ,guid
  17769. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17770. json_object_put(StopTransaction);
  17771. // Check File "TempStopTransaction" Exist
  17772. if((access(TempStopTransaction,F_OK))!=-1)
  17773. {
  17774. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17775. fclose(fopen(TempStopTransaction, "w"));
  17776. }
  17777. else
  17778. {
  17779. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17780. FILE *log = fopen(TempStopTransaction, "w+");
  17781. if(log == NULL)
  17782. {
  17783. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17784. return ;
  17785. }
  17786. else
  17787. {
  17788. fclose(log);
  17789. }
  17790. }
  17791. //Add TempStopTransaction | Update TempStopTransaction
  17792. // open file for writing
  17793. FILE *outfile;
  17794. outfile = fopen (TempStopTransaction, "a");
  17795. //DEBUG_INFO("data = %s\n", queuedata);
  17796. fputs(queuedata, outfile);
  17797. fputs("\n", outfile);
  17798. fclose (outfile);
  17799. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17800. OCPP_updatePeriodEnergy(gun_index);
  17801. }
  17802. void checkTempStopTransaction(int gun_index)
  17803. {
  17804. FILE *fptr1;
  17805. char ch;
  17806. char str[QUEUE_MESSAGE_LENGTH]={0};
  17807. char guid[37]={0};
  17808. char tempdata[65]={0};
  17809. char connectorStr[2]={0};
  17810. char TempStopTransaction[256];
  17811. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17812. fptr1 = fopen(TempStopTransaction, "r");
  17813. //TempStopTransaction格式: 槍號,StopTransaction封包
  17814. if (!fptr1)
  17815. {
  17816. //printf(" File not found or unable to open the input file!!\n");
  17817. return ;
  17818. }
  17819. ch=fgetc(fptr1);
  17820. //printf(" Now the content of the file %s is : \n",fname);
  17821. rewind(fptr1);
  17822. if(ch!=EOF)
  17823. {
  17824. // copy all contents to the temporary file except the specific line
  17825. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17826. {
  17827. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17828. if(str[0]=='\0')
  17829. {
  17830. break;
  17831. }
  17832. //TempStopTransaction格式: 槍號,StopTransaction封包
  17833. strncpy(connectorStr, str, 1);
  17834. if(atoi(connectorStr) != (gun_index+1))
  17835. {
  17836. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17837. fclose(fptr1);
  17838. return ;
  17839. }
  17840. //random_uuid(guid);
  17841. strncpy(guid, str+6, 36); //copy guid
  17842. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17844. {
  17845. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17846. }
  17847. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17848. OCPP_insert_transaction_msg(NO, str);
  17849. memset(str,0,ARRAY_SIZE(str));
  17850. }
  17851. }
  17852. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17853. fclose(fptr1);
  17854. remove(TempStopTransaction); // remove the original file
  17855. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17856. }
  17857. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17858. {
  17859. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17860. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17861. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17862. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17863. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17864. }
  17865. int GetWebSocketPingInterval(void)
  17866. {
  17867. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17868. }
  17869. int GetServerSign(void)
  17870. {
  17871. return server_sign;
  17872. }
  17873. uint8_t GetOcppSecurityProfile()
  17874. {
  17875. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17876. }
  17877. void GetOcppChargerBoxId(uint8_t *data)
  17878. {
  17879. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17880. }
  17881. void GetOcppSecurityPassword(uint8_t *data)
  17882. {
  17883. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17884. }
  17885. void SetOcppVersion(uint8_t *version)
  17886. {
  17887. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17888. DEBUG_INFO("ocpp version: %s\n", version);
  17889. if(strstr((char*)version, "ocpp1.6") != NULL)
  17890. {
  17891. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17892. }
  17893. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17894. {
  17895. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17896. system("pkill OcppBackend");
  17897. }
  17898. }
  17899. void SetServerSign(int value)
  17900. {
  17901. server_sign = value;
  17902. }
  17903. int GetBootNotificationInterval(void)
  17904. {
  17905. return BootNotificationInterval;
  17906. }
  17907. int GetInternetConn(void)
  17908. {
  17909. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17910. }
  17911. int GetBackendConnectionTimeout(void)
  17912. {
  17913. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17914. }
  17915. int isConnectorInitMode(int gun_index)
  17916. {
  17917. int tempIndex = 0;
  17918. int result = TRUE;
  17919. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17921. {
  17922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17923. {
  17924. tempIndex = ((gun_index==2) ? 1: 0);
  17925. }
  17926. else
  17927. {
  17928. tempIndex = gun_index;
  17929. }
  17930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17931. {
  17932. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17933. {
  17934. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17935. } //end of the same index
  17936. }//end of for CHAdeMO_QUANTITY
  17937. }
  17938. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17939. {
  17940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17941. {
  17942. tempIndex = ((gun_index==2) ? 1: 0);
  17943. }
  17944. else
  17945. {
  17946. tempIndex = gun_index;
  17947. }
  17948. for (int index = 0; index < CCS_QUANTITY; index++)
  17949. {
  17950. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17951. {
  17952. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17953. } //end of the same index
  17954. } // end of for CCS_QUANTITY
  17955. }
  17956. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17957. {
  17958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17959. {
  17960. tempIndex = ((gun_index==2) ? 1: 0);
  17961. }
  17962. else
  17963. {
  17964. tempIndex = gun_index;
  17965. }
  17966. for (int index = 0; index < GB_QUANTITY; index++)
  17967. {
  17968. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17969. {
  17970. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17971. } //end of the same index
  17972. } // end of for GB_QUANTITY
  17973. }
  17974. else if(gunType[gun_index] == GUN_TYPE_DO)
  17975. {
  17976. tempIndex = gun_index;
  17977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17978. {
  17979. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17980. {
  17981. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17982. } //end of the same index
  17983. }
  17984. }
  17985. else
  17986. {
  17987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17988. {
  17989. tempIndex = 2;
  17990. }
  17991. else
  17992. {
  17993. tempIndex = gun_index;
  17994. }
  17995. for (int index = 0; index < AC_QUANTITY; index++)
  17996. {
  17997. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17998. {
  17999. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18000. }//end of the same index
  18001. }//end of for AC_QUANTITY
  18002. }
  18003. return result;
  18004. }
  18005. void refreshProcDogTimer()
  18006. {
  18007. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18008. }
  18009. void InitialSystemValue(void)
  18010. {
  18011. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18012. locallistVersion=0;
  18013. BootNotificationInterval = 0;
  18014. authorizeRetryTimes = 0;
  18015. GunStatusInterval = 10;
  18016. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18017. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18018. //Hear Beat
  18019. HeartBeatWithNOResponse = 0;
  18020. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18021. FirstHeartBeat = 0;
  18022. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18023. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18024. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18025. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18026. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18027. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18028. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18029. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18030. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18031. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18032. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18033. //Status && ConnectorPlugIn Setting
  18034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18035. {
  18036. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18037. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18038. }
  18039. for (int index = 0; index < CCS_QUANTITY; index++)
  18040. {
  18041. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18042. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18043. }
  18044. for (int index = 0; index < GB_QUANTITY; index++)
  18045. {
  18046. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18047. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18048. }
  18049. for (int index = 0; index < AC_QUANTITY; index++)
  18050. {
  18051. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18052. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18053. }
  18054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18055. {
  18056. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18057. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18058. }
  18059. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18060. {
  18061. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18062. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18063. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18064. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18065. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18066. }
  18067. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18068. refreshStartTimer(&clientTime.Heartbeat);
  18069. sleep(1);
  18070. }
  18071. void LWS_Send(char *str)
  18072. {
  18073. //=====================================================
  18074. // Check InternetConn 0: disconnected, 1: connected
  18075. //====================================================
  18076. if(GetOcppConnStatus() == 0)
  18077. {
  18078. DEBUG_INFO("offline now !!!\n");
  18079. return;
  18080. }
  18081. // Only disable isWebsocketSendable operation initiated by charger
  18082. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18083. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18084. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18085. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18086. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18087. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18088. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18089. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18090. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18091. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18092. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18093. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18094. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18095. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18096. {
  18097. isWebsocketSendable = 0;
  18098. }
  18099. pthread_mutex_lock(&lock_send);
  18100. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18101. sprintf((char *)SendBuffer, "%s", str);
  18102. SendBufLen = strlen(str);
  18103. pthread_mutex_unlock(&lock_send);
  18104. lws_callback_on_writable(wsi_client);
  18105. //lws_service(context, 0);
  18106. //sleep(1);
  18107. }
  18108. void LWS_SendNow(char *str)
  18109. {
  18110. //=====================================================
  18111. // Check InternetConn 0: disconnected, 1: connected
  18112. //====================================================
  18113. if(GetOcppConnStatus() == 0)
  18114. {
  18115. DEBUG_INFO("offline now !!!\n");
  18116. return;
  18117. }
  18118. // Only disable isWebsocketSendable operation initiated by charger
  18119. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18120. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18121. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18122. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18123. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18124. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18125. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18126. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18127. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18128. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18129. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18130. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18131. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18132. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18133. {
  18134. isWebsocketSendable = 0;
  18135. }
  18136. pthread_mutex_lock(&lock_send);
  18137. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18138. sprintf((char *)SendBuffer, "%s", str);
  18139. SendBufLen = strlen(str);
  18140. pthread_mutex_unlock(&lock_send);
  18141. lws_callback_on_writable(wsi_client);
  18142. lws_service(context, 0);
  18143. //sleep(1);
  18144. }